[Zetaback-devel] [zetaback commit] r94 - branches/replay
svn-commit at lists.omniti.com
svn-commit at lists.omniti.com
Wed Jun 10 15:30:04 EDT 2009
Author: mark
Date: 2009-06-10 15:30:04 -0400 (Wed, 10 Jun 2009)
New Revision: 94
Modified:
branches/replay/zetaback.in
Log:
Some cleanup and adding scanning for dataset based backups
Modified: branches/replay/zetaback.in
===================================================================
--- branches/replay/zetaback.in 2009-06-08 21:03:49 UTC (rev 93)
+++ branches/replay/zetaback.in 2009-06-10 19:30:04 UTC (rev 94)
@@ -476,6 +476,7 @@
my %info = ();
my $dir = shift;
$info{last_full} = $info{last_incremental} = $info{last_backup} = 0;
+ # Look for standard file based backups first
opendir(D, $dir) || return \%info;
foreach my $file (readdir(D)) {
if($file =~ /^(\d+)\.([^\.]+)\.full$/) {
@@ -497,6 +498,28 @@
}
}
closedir(D);
+ # Now look for zfs based backups
+ my $storefs;
+ eval {
+ $storefs = get_fs_from_mountpoint($dir);
+ };
+ return \%info if ($@);
+ my $rv = open(ZFSLIST, "__ZFS__ list -H -r -t snapshot $storefs |");
+ return \%info unless $rv;
+ while (<ZFSLIST>) {
+ my @F = split(' ');
+ my ($fs, $snap) = split('@', $F[0]);
+ my $whence = ($snap =~ /__zb_dset_(\d+)/);
+ $info{$fs}->{full}->{$whence}->{'snapshot'} = $snap;
+ # TODO - the info may need to be different here - no last_full or
+ # last_incremental
+ #$info{$fs}->{last_full} = $whence if($whence > $info{$fs}->{last_full});
+ $info{$fs}->{last_backup} = $whence if ($whence >
+ $info{$fs}->{last_backup});
+ }
+ close(ZFSLIST);
+ die "Unable to determine zfs filesystem for $dir" unless $storefs;
+
return \%info;
}
@@ -557,8 +580,8 @@
my @cmd = ('ssh', split(/ /, $ssh_config), $host, $agent, '-z', $fs, "-$type", $point);
open STDIN, "/dev/null" || exit(-1);
if ($type eq "d") {
- # TODO - specify the filesystem name to receive to here
- open STDOUT, "|zfs recv $dumpname"
+ my $storefs = get_fs_from_mountpoint($store);
+ open STDOUT, "|__ZFS__ recv $storefs/$dumpname"
} else {
open STDOUT, ">&LBACKUP" || exit(-1);
}
@@ -585,8 +608,7 @@
my @st = stat("$store/$dumpname");
$size = pretty_size($st[7]);
} else {
- # TODO - get correct name of the snapshot here in place of dumpname
- $size = `zfs get -Ho value used $dumpname`;
+ $size = `__ZFS__ get -Ho value used $dumpname`;
}
zetaback_log($host, "SUCCESS[$size] $host:$fs $type\n");
}
@@ -619,7 +641,8 @@
my $agent = config_get($host, 'agent');
my $point = time();
- # TODO - either put the filesystem
+ # Replace slashes with underscores in the fs name
+ my $efs = ($fs =~ s/\//_/g);
my $dumpname = "$host/$fs\@$point";
zfs_do_backup($host, $fs, 'd', $base, $store, $dumpname);
@@ -739,6 +762,23 @@
return @list;
}
+sub get_fs_from_mountpoint($) {
+ my ($mountpoint) = @_;
+ my $fs;
+ my $rv = open(ZFSLIST, "__ZFS__ list -H |");
+ die "Unable to determine zfs filesystem for $mountpoint" unless $rv;
+ while (<ZFSLIST>) {
+ my @F = split(' ');
+ if ($F[-1] eq $mountpoint) {
+ $fs = $F[0];
+ last;
+ }
+ }
+ close(ZFSLIST);
+ die "Unable to determine zfs filesystem for $mountpoint" unless $fs;
+ return $fs;
+}
+
sub perform_restore() {
my %source;
@@ -953,6 +993,8 @@
# We need a lock for the listing.
return unless(lock($host, ".list"));
+
+ # Get list of zfs filesystems from the agent
open(SILENT, ">&", \*STDERR);
close(STDERR);
my $rv = open(ZFSLIST, "ssh $ssh_config $host $agent -l |");
More information about the Zetaback-devel
mailing list