5 use File
::Path
qw(rmtree);
11 my $time_str = POSIX
::strftime
("%Y.%m.%d-%H.%M.%S" , localtime());
12 my $snap_path = $base_path . "/.snapshots/\@GMT-" . $time_str;
15 POSIX
::mkdir($base_path . "/.snapshots", 0777);
17 # add trailing slash to src path to ensure that only contents is copied
18 $ret = system("rsync", "-a", "--exclude=.snapshots/", "${base_path}/",
21 print STDERR
"rsync failed with $ret\n";
31 my ($base_path, $snap_path) = @_;
33 # we're doing a recursive delete, so do some sanity checks
34 if ((index($snap_path, $base_path) != 0) || (index($snap_path, ".snapshots") == -1)) {
35 print STDERR
"invalid snap_path: $snap_path\n";
39 rmtree
($snap_path, {error
=> \
my $err});
41 for my $diag (@
$err) {
42 my ($file, $message) = %$diag;
44 print STDERR
"rmtree error: $message\n";
46 print STDERR
"rmtree error $file: $message\n";
56 my $num_args = $#ARGV + 1;
59 if (($num_args == 2) && ($cmd eq "--check")) {
61 } elsif (($num_args == 2) && ($cmd eq "--create")) {
62 $ret = _create_snapshot
($ARGV[0]);
63 } elsif (($num_args == 3) && ($cmd eq "--delete")) {
64 $ret = _delete_snapshot
($ARGV[0], $ARGV[1]);
66 print STDERR
"invalid script argument\n";