-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
delete-scheduled-backup.pl
executable file
·82 lines (71 loc) · 1.93 KB
/
delete-scheduled-backup.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/local/bin/perl
=head1 delete-scheduled-backup.pl
Delete a scheduled backup for one or more virtual servers
This command removes the scheduled backup identified with the C<--id> flag,
which must be followed by the backup's unique numeric ID. Or you can select
a backup with C<--dest> followed by a backup destination path.
This only prevents future backups from happening on schedule, and it does not
remove any existing backup files.
=cut
package virtual_server;
if (!$module_name) {
$main::no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*)\/[^\/]+$/) {
chdir($pwd = $1);
}
else {
chop($pwd = `pwd`);
}
$0 = "$pwd/delete-scheduled-backup.pl";
require './virtual-server-lib.pl';
$< == 0 || die "delete-scheduled-backup.pl must be run as root";
}
&licence_status();
# Parse command-line args
@OLDARGV = @ARGV;
while(@ARGV > 0) {
local $a = shift(@ARGV);
if ($a eq "--id") {
$id = shift(@ARGV);
}
elsif ($a eq "--dest") {
$dest = shift(@ARGV);
}
elsif ($a eq "--multiline") {
$multiline = 1;
}
elsif ($a eq "--help") {
&usage();
}
else {
&usage("Unknown parameter $a");
}
}
# Get the backup to remove
if ($id) {
($sched) = grep { $_->{'id'} eq $id } &list_scheduled_backups();
$sched || &usage("No backup with ID $id exists");
}
elsif ($dest) {
($sched) = grep { &indexof($dest, &get_scheduled_backup_dests($_)) >= 0 } &list_scheduled_backups();
$sched || &usage("No backup with destination $dest exists");
}
else {
&usage("Missing --id or --dest parameters");
}
&delete_scheduled_backup($sched);
print "Scheduled backup deleted with ID $sched->{'id'}\n";
&virtualmin_api_log(\@OLDARGV);
sub usage
{
if ($_[0]) {
print $_[0],"\n\n";
}
print "Delete a scheduled backup for one or more virtual servers.\n";
print "\n";
print "virtualmin delete-scheduled-backup [--id number]\n";
print " [--dest path]\n";
exit(1);
}