[Zetaback-devel] [zetaback commit] r121 - branches/sendr
svn-commit at lists.omniti.com
svn-commit at lists.omniti.com
Thu Oct 1 17:54:47 EDT 2009
Author: mark
Date: 2009-10-01 17:54:46 -0400 (Thu, 01 Oct 2009)
New Revision: 121
Modified:
branches/sendr/zetaback.in
branches/sendr/zetaback_agent.in
Log:
Merge branch 'senddashr' into sendr
Modified: branches/sendr/zetaback.in
===================================================================
--- branches/sendr/zetaback.in 2009-10-01 21:52:30 UTC (rev 120)
+++ branches/sendr/zetaback.in 2009-10-01 21:54:46 UTC (rev 121)
@@ -31,6 +31,7 @@
$conf{'default'}->{'retention'} = 14 * 86400;
$conf{'default'}->{'compressionlevel'} = 1;
$conf{'default'}->{'dataset_backup'} = 0;
+$conf{'default'}->{'dataset_recursive'} = 0;
=pod
@@ -366,6 +367,14 @@
By default zetaback backs zfs filesystems up to files. This option lets you
specify that the backup go be stored as a zfs dataset on the backup host.
+=item dataset_recursive
+
+If dataset backups are enabled, this specifies that the -R option to zfs send
+be used to recursively send child filesystems across all at once. The -R
+option was only introduced in Solaris 10 8/07 (u4) and so that release or a
+later release must be used on all machines being backed up, as well as the
+backup server itself.
+
=back
=head1 CONFIGURATION EXAMPLES
@@ -603,7 +612,7 @@
# Lots of args.. internally called.
sub zfs_do_backup($$$$$$;$) {
my ($host, $fs, $type, $point, $store, $dumpname, $base) = @_;
- my ($storefs, $encodedname);
+ my ($storefs, $fsname);
my $agent = config_get($host, 'agent');
my $ssh_config = config_get($host, 'ssh_config');
$ssh_config = "-F $ssh_config" if($ssh_config);
@@ -632,11 +641,24 @@
$storefs = get_fs_from_mountpoint($basestore);
$storefs="$storefs/$host";
}
- $encodedname = fs_encode($dumpname);
- print STDERR "Receiving to zfs filesystem $storefs/$encodedname\n"
+ my $recvopt = "";
+ my $fsname = $dumpname;
+ if (config_get($host, 'dataset_recursive') == 0) {
+ # TODO - fsname might need to be changed to just the hostname
+ $recvopt = "-d";
+ } else {
+ $fsname = fs_encode($fsname);
+ }
+ print STDERR "Receiving to zfs filesystem $storefs/$fsname\n"
if($DEBUG);
- zfs_create_intermediate_filesystems("$storefs/$encodedname");
- open(LBACKUP, "|__ZFS__ recv $storefs/$encodedname");
+ if (config_get($host, 'dataset_recursive') == 1) {
+ # Create all filesystems, including the destination one
+ zfs_create_intermediate_filesystems("$storefs/$fsname/");
+ } else {
+ # Create intermediate filesystems
+ zfs_create_intermediate_filesystems("$storefs/$fsname");
+ }
+ open(LBACKUP, "|__ZFS__ recv $recvopt $storefs/$fsname");
}
# Do it. yeah.
eval {
@@ -665,8 +687,8 @@
rename("$store/.$dumpname", "$store/$dumpname") || die "cannot rename dump\n";
} else {
# Check everything is ok
- `__ZFS__ list $storefs/$encodedname`;
- die "dump failed (received snapshot $storefs/$encodedname does not exist)\n"
+ `__ZFS__ list $storefs/$fsname`;
+ die "dump failed (received snapshot $storefs/$fsname does not exist)\n"
if $?;
}
};
@@ -684,7 +706,7 @@
my @st = stat("$store/$dumpname");
$size = pretty_size($st[7]);
} else {
- $size = `__ZFS__ get -Ho value used $storefs/$encodedname`;
+ $size = `__ZFS__ get -Ho value used $storefs/$fsname`;
chomp $size;
}
zetaback_log($host, "SUCCESS[$size] $host:$fs $type\n");
Modified: branches/sendr/zetaback_agent.in
===================================================================
--- branches/sendr/zetaback_agent.in 2009-10-01 21:52:30 UTC (rev 120)
+++ branches/sendr/zetaback_agent.in 2009-10-01 21:54:46 UTC (rev 121)
@@ -11,7 +11,7 @@
use vars qw/%conf $version_string
$PREFIX $CONF $LIST $FULL $SNAP $ZFS $BASE $RESTORE $VERSION
- $BUG_6343779 $NEEDSFD $DSET/;
+ $BUG_6343779 $NEEDSFD $DSET $DSET_RECURSE/;
$version_string = '0.1';
$PREFIX = q^__PREFIX__^;
$CONF = qq^$PREFIX/etc/zetaback_agent.conf^;
@@ -27,7 +27,7 @@
zetaback_agent -v
- zetaback_agent -l [-c conf]
+ zetaback_agent -l [-sr] [-c conf]
zetaback_agent -r [-b <timestamp>] [-c conf] [-z zfs]
@@ -35,8 +35,10 @@
zetaback -i <timestamp> [-c conf] [-z zfs]
- zetaback -d <snap> -z <zfs> [-c conf]
+ zetaback -s <timestamp> [-i <timestamp>] [-sr] [-c conf] [-z zfs]
+ zetaback -d <snap> [-sr] -z <zfs> [-c conf]
+
=cut
GetOptions(
@@ -48,6 +50,7 @@
"f=s" => \$FULL,
"i=s" => \$BASE,
"s=s" => \$DSET,
+ "sr" => \$DSET_RECURSE,
"b=s" => \$BUG_6343779,
"v" => \$VERSION,
);
@@ -93,6 +96,11 @@
<timestamp>, which is provided by the backup server. This requires the -i
option to specify the base dataset the expected by the backup server.
+=item -sr
+
+Specifies that any dataset backup should be recursive. When used in
+combination with -l, don't list any child filesystems.
+
=item -l
List ZFS filesystems.
@@ -203,7 +211,13 @@
else {
die "zfs_agent_remove_snap: illegal snap: $SNAP\n";
}
- `__ZFS__ destroy $target`;
+ if ($DSET_RECURSE) {
+ # If we recursively destroy a snapshot, snapshots with the same name in
+ # child filesystems are deleted also
+ `__ZFS__ destroy -r $target`;
+ } else {
+ `__ZFS__ destroy $target`;
+ }
}
sub zfs_agent_perform_full {
@@ -243,15 +257,21 @@
unless($ZFS && $DSET) {
die "zfs_agent_perform_dataset: bad args\n"
}
- `__ZFS__ snapshot $target`;
+ if ($DSET_RECURSE) {
+ `__ZFS__ snapshot -r $target`;
+ } else {
+ `__ZFS__ snapshot $target`;
+ }
# $BASE (the base snapshot) is optional. If provided, send an incremental
# snapshot
- my @cmd;
+ my @cmd = ("__ZFS__", "send");
+ if ($DSET_RECURSE) {
+ push(@cmd, "-R");
+ }
if ($BASE) {
- @cmd = ("__ZFS__", "send", "-i", $base, $target);
- } else {
- @cmd = ("__ZFS__", "send", $target);
+ push(@cmd, "-i", $base);
}
+ push(@cmd, $target);
if($NEEDSFD) {
fifo_exec(@cmd);
} else {
@@ -269,13 +289,31 @@
(my $fs = $line[0]) =~ s/\@.+//;
my $excl = (split(/\s+/,`__ZFS__ get -H com.omniti.labs.zetaback:exclude $fs`))[2];
if(($excl ne "on") && ($fs =~ /$conf{pattern}/)) {
+ my $fsname = $line[0];
+ my $snapname = "";
if($line[0] =~ /(\S+)\@([^\@]+)$/) {
- $zfs{$1} ||= [];
- push @{$zfs{$1}}, $2;
+ $fsname = $1;
+ $snapname = $2;
}
- else {
- $zfs{$line[0]} ||= [];
+ if ($DSET_RECURSE) {
+ # We don't display child filesystems if the parent has already been
+ # listed and we are using zfs send -R
+ my $match = 0;
+ foreach my $existingfs (keys %zfs) {
+ # Look to see if the current filesystem is a child of a filesystem
+ # we already added to the list
+ if (substr($fsname, 0, length($existingfs)) eq $existingfs) {
+ $match = 1;
+ last;
+ }
+ }
+ # Skip this filesystem if we had a match previously
+ if ($match) { next; }
}
+ $zfs{$fsname} ||= [];
+ if ($snapname ne "") {
+ push @{$zfs{$fsname}}, $snapname;
+ }
}
}
close(ZFSLIST);
More information about the Zetaback-devel
mailing list