summaryrefslogtreecommitdiffstats
path: root/source3/script
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@samba.org>2013-12-03 14:45:49 +0100
committerMichael Adam <obnox@samba.org>2013-12-05 00:47:52 +0100
commit29b730a4487410e4bdb42d970dc21fe235dce654 (patch)
tree7cb36dba250657ab8a12ab0becfe6808d7294611 /source3/script
parentb0bbb59c49bd068a0a8feea76b2564da8cfabb11 (diff)
downloadsamba-29b730a4487410e4bdb42d970dc21fe235dce654.tar.gz
samba-29b730a4487410e4bdb42d970dc21fe235dce654.tar.xz
samba-29b730a4487410e4bdb42d970dc21fe235dce654.zip
test: add fake_snap.pl for snapshot simulation
The script simulates snapshots by simply copying file data from the base path to a snapshot path located under .snapshots/@GMT-%Y.%m.%d-%H.%M.%S/ Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/script')
-rwxr-xr-xsource3/script/tests/fake_snap.pl70
1 files changed, 70 insertions, 0 deletions
diff --git a/source3/script/tests/fake_snap.pl b/source3/script/tests/fake_snap.pl
new file mode 100755
index 00000000000..d1233f375b0
--- /dev/null
+++ b/source3/script/tests/fake_snap.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use File::Path qw(rmtree);
+use POSIX ();
+
+sub _create_snapshot
+{
+ my ($base_path) = @_;
+ my $time_str = POSIX::strftime("%Y.%m.%d-%H.%M.%S" , localtime());
+ my $snap_path = $base_path . "/.snapshots/\@GMT-" . $time_str;
+ my $ret;
+
+ POSIX::mkdir($base_path . "/.snapshots", 0777);
+
+ # add trailing slash to src path to ensure that only contents is copied
+ $ret = system("rsync", "-a", "--exclude=.snapshots/", "${base_path}/",
+ $snap_path);
+ if ($ret != 0) {
+ print STDERR "rsync failed with $ret\n";
+ } else {
+ print "$snap_path\n";
+ }
+
+ return $ret;
+}
+
+sub _delete_snapshot
+{
+ my ($base_path, $snap_path) = @_;
+
+ # we're doing a recursive delete, so do some sanity checks
+ if ((index($snap_path, $base_path) != 0) || (index($snap_path, ".snapshots") == -1)) {
+ print STDERR "invalid snap_path: $snap_path\n";
+ return -1;
+ }
+
+ rmtree($snap_path, {error => \my $err});
+ if (@$err) {
+ for my $diag (@$err) {
+ my ($file, $message) = %$diag;
+ if ($file eq '') {
+ print STDERR "rmtree error: $message\n";
+ } else {
+ print STDERR "rmtree error $file: $message\n";
+ }
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+my $ret;
+my $num_args = $#ARGV + 1;
+my $cmd = shift;
+
+if (($num_args == 2) && ($cmd eq "--check")) {
+ $ret = 0;
+} elsif (($num_args == 2) && ($cmd eq "--create")) {
+ $ret = _create_snapshot($ARGV[0]);
+} elsif (($num_args == 3) && ($cmd eq "--delete")) {
+ $ret = _delete_snapshot($ARGV[0], $ARGV[1]);
+} else {
+ print STDERR "invalid script argument\n";
+ $ret = -1;
+}
+
+exit $ret;