Add README and cleanup the script
This commit is contained in:
parent
21030f2a02
commit
f2ce80cf2b
2 changed files with 70 additions and 36 deletions
34
README.md
Normal file
34
README.md
Normal file
|
@ -0,0 +1,34 @@
|
|||
Script to queue backup in BackupPC from command line
|
||||
====================================================
|
||||
|
||||
This script permit to queue backup (for all or specified host(s)) in BackupPC from
|
||||
command line. It's provide parameters permiting :
|
||||
|
||||
* to specify witch type of backup to queue (full or incr) ;
|
||||
* to specify as wich user the backup is run for BackupPC ;
|
||||
* to stop running backup instead of starting new one, and how many hour(s) BackupPC could not start automatically backup ;
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
'''
|
||||
backuppcQueueBackup
|
||||
|
||||
Script to queue backup in BackupPC from command line
|
||||
|
||||
Options:
|
||||
--verbose,-v Increase verbosity
|
||||
--help,-h Display this message
|
||||
|
||||
--hostname,-H Only queue backup for the specified host
|
||||
--exclude,-x Do not queue backup for the specified host
|
||||
--all,-a queue backup for all BackupPC hosts
|
||||
--start-first,-f Start first queuing backup for this specified host(s)
|
||||
--includeBackupsDisableHosts Queue backup for all BackupPC hosts
|
||||
--type,-t Backup type : full or incr
|
||||
--user,-u BackupPC user that doing this action for BackupPC
|
||||
--stop Stop Backup instead of queuing new one
|
||||
--backoff During stop Backup action, say BackupPC do not automatically
|
||||
start backup during next x hour(s) (Default : 1 hour(s))
|
||||
--dry-run,-j Perform a trial run (do nothing real)
|
||||
'''
|
|
@ -27,22 +27,22 @@ my $all = 0;
|
|||
|
||||
|
||||
$goodOpt = GetOptions(
|
||||
'v+' => \$verbose, 'verbose+' => \$verbose,
|
||||
't=s' => \$opt_t, 'type=s' => \$opt_t,
|
||||
'stop+' => \$stop,
|
||||
'includeBackupsDisableHosts+' => \$includeBackupsDisableHosts,
|
||||
'backoff=i' => \$stop_backoff,
|
||||
'h' => \$opt_h, 'help' => \$opt_h,
|
||||
'u=s' => \$user, 'user=s' => \$user,
|
||||
'j+' => \$dry_run, 'dry-run+' => \$dry_run,
|
||||
'a+' => \$all, 'all+' => \$all,
|
||||
'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
|
||||
'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded,
|
||||
'f=s' => \@hostsStartFirst, 'start-first=s' => \@hostsStartFirst);
|
||||
'v+' => \$verbose, 'verbose+' => \$verbose,
|
||||
't=s' => \$opt_t, 'type=s' => \$opt_t,
|
||||
'stop+' => \$stop,
|
||||
'includeBackupsDisableHosts+' => \$includeBackupsDisableHosts,
|
||||
'backoff=i' => \$stop_backoff,
|
||||
'h' => \$opt_h, 'help' => \$opt_h,
|
||||
'u=s' => \$user, 'user=s' => \$user,
|
||||
'j+' => \$dry_run, 'dry-run+' => \$dry_run,
|
||||
'a+' => \$all, 'all+' => \$all,
|
||||
'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
|
||||
'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded,
|
||||
'f=s' => \@hostsStartFirst, 'start-first=s' => \@hostsStartFirst);
|
||||
|
||||
if ($all == 0 && $#hostsDesired < 0 && $#hostsExcluded < 0) {
|
||||
print " ERROR : You must specify on witch host(s) you want to queue backup using\n";
|
||||
print " at least one of --all, --hostname or --exclude parameters.\n";
|
||||
print " at least one of --all, --hostname or --exclude parameters.\n\n";
|
||||
$goodOpt=0;
|
||||
}
|
||||
|
||||
|
@ -57,22 +57,22 @@ if ($opt_t ne "full" && $opt_t ne "incr") {
|
|||
}
|
||||
|
||||
if ($opt_h or not $goodOpt) {
|
||||
print "BackupPC_queue_backup\n\n";
|
||||
print "backuppcQueueBackup\n\n";
|
||||
print "Script to queue backup in BackupPC internal queue\n\n";
|
||||
print "Options:\n";
|
||||
print " --verbose,-v increase verbosity\n";
|
||||
print " --help,-h display this message\n\n";
|
||||
print " --hostname,-H only queue backup for the specified host\n";
|
||||
print " --exclude,-x do not queue backup for the specified host\n";
|
||||
print " --all,-a queue backup for all BackupPC hosts\n";
|
||||
print " --start-first,-f Start first queuing backup for this specified host(s)\n";
|
||||
print " --includeBackupsDisableHosts queue backup for all BackupPC hosts\n";
|
||||
print " --type,-t Backup type : full or incr\n";
|
||||
print " --user,-u BackupPC user that doing this action for BackupPC\n";
|
||||
print " --stop Stop Backup instead of queuing new one\n";
|
||||
print " --backoff During stop Backup action, say BackupPC do not automatically\n";
|
||||
print " start backup during next x hour(s) (Default : $stop_backoff hour(s))\n";
|
||||
print " --dry-run,-j Perform a trial run (do nothing real)\n";
|
||||
print " --verbose,-v Increase verbosity\n";
|
||||
print " --help,-h Display this message\n\n";
|
||||
print " --hostname,-H Only queue backup for the specified host\n";
|
||||
print " --exclude,-x Do not queue backup for the specified host\n";
|
||||
print " --all,-a Queue backup for all BackupPC hosts\n";
|
||||
print " --start-first,-f Start first queuing backup for this specified host(s)\n";
|
||||
print " --includeBackupsDisableHosts Queue backup for all BackupPC hosts\n";
|
||||
print " --type,-t Backup type : full or incr\n";
|
||||
print " --user,-u BackupPC user that doing this action for BackupPC\n";
|
||||
print " --stop Stop Backup instead of queuing new one\n";
|
||||
print " --backoff During stop Backup action, say BackupPC do not automatically\n";
|
||||
print " Start backup during next x hour(s)\n";
|
||||
print " --dry-run,-j Perform a trial run (do nothing real)\n";
|
||||
exit 0 if $goodOpt;
|
||||
exit 1;
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ if ($opt_h or not $goodOpt) {
|
|||
my $server;
|
||||
if (!($server = BackupPC::Lib->new))
|
||||
{
|
||||
print "Couldn't connect to BackupPC\n";
|
||||
exit 1;
|
||||
print "Couldn't connect to BackupPC\n";
|
||||
exit 1;
|
||||
}
|
||||
my %Conf = $server->Conf();
|
||||
|
||||
|
@ -91,8 +91,8 @@ $server->ChildInit();
|
|||
my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
|
||||
if ($err)
|
||||
{
|
||||
print("Can't connect to server ($err)\n");
|
||||
exit 1;
|
||||
print("Can't connect to server ($err)\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# query the BackupPC server for host status
|
||||
|
@ -105,11 +105,11 @@ eval $status_raw;
|
|||
|
||||
foreach my $host (@hostsDesired, @hostsExcluded, @hostsStartFirst)
|
||||
{
|
||||
if (not grep {/^$host$/} keys(%Status))
|
||||
{
|
||||
print("Unknown host ($host)\n");
|
||||
exit 1;
|
||||
}
|
||||
if (not grep {/^$host$/} keys(%Status))
|
||||
{
|
||||
print("Unknown host ($host)\n");
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
# Common parameters
|
||||
|
|
Loading…
Reference in a new issue