Wrong button ...

here it is. Against 1.2.1

On Friday 04 March 2011 22.24:46 Adrian von Bidder wrote:
> Heyho!
> 
> I had a few moments to spare recently...
> 
> Summary: support using btrfs snapshots instead of hardlinked rsync trees.
> Also uses the --inplace option to rsync, so for changed files only the
> modified parts will be duplicated. (Hmm. rsync doesn't use fallocate(2)
> to punch holes in files yet, I assume, so there's room for improvement
> here for cases where a piece of a file has been cut out, as in a video
> stream.)
> 
> Also: a (first?) batch of patches that support data deduplication has
> been posted to the btrfs mailing list in January, so btrfs will be even
> more interesting in the medium future for those who use dirvish to
> backup a number of similar machines to a central backup machine. Not
> sure when this will be really available though...
> 
> Change vs. the first versions: as was proposed in the original discussion
> of this, the "btrfs" option has now been renamed into "cow" (copy on
> write); supported values are 0 (default) and btrfs. Supporting other cow
> filesystems is left as an exercise to the reader.
> 
> Status: while this is running here, I've only just written this code a
> few days ago, so some testing / feedback is welcome.
> 
> Since I expect there are not that many users of this yet, no migration
> path for old vaults is provided, I didn't want to bloat the code with
> support code for stuff that wasn't even released. Just insert "cow:
> btrfs" into all summary files (and default.conf, of course) and you're
> fine.
> 
> cheers
> -- vbi

-- 
The Free Software Foundation: The gang that couldn't price-fix straight!
diff --git a/dirvish-expire.pl b/dirvish-expire.pl
--- a/dirvish-expire.pl
+++ b/dirvish-expire.pl
@@ -166,7 +166,12 @@
 
 	$$Options{'no-run'} and next;
 
-	system("rm -rf $$expire{path}/tree");
+        if (lc $$expire{cow} eq 'btrfs')
+        {
+                system("btrfs subvolume delete $$expire{path}/tree > /dev/null");
+        } else {
+                system("rm -rf $$expire{path}/tree");
+        }
 	$$Options{tree} and next;
 
 	system("rm -rf $$expire{path}");
@@ -237,6 +242,7 @@
 				created	=> $$summary{'Backup-complete'},
 				expire	=> $$summary{Expire},
 				status	=> $$summary{Status},
+				cow	=> $$summary{cow},
 				path	=> $path,
 			}
 		);
diff --git a/dirvish.conf.5 b/dirvish.conf.5
--- a/dirvish.conf.5
+++ b/dirvish.conf.5
@@ -197,6 +197,13 @@
 
 .default 0
 .TP
+.Bi cow: (S)
+Specifies that a copy on write filesysstem should be used.  The only supported
+values are currently 0 (default) and \fBbtrfs\fP, which will use btrfs
+snapshots instead of hardlinked trees. The \fBbtrfs\fP utility needs to be in
+$PATH (it usually resides in /usr/sbin, which is not included in cron's default
+$PATH.)
+.TP
 .Bi config: filename (S)
 Load configuration file.
 
diff --git a/dirvish.pl b/dirvish.pl
--- a/dirvish.pl
+++ b/dirvish.pl
@@ -200,6 +200,7 @@
 			exit(0);
 		},
 	help		=> \&usage,
+	cow		=> 0,
 };
 
 if ($CONFDIR =~ /dirvish$/ && -f "$CONFDIR.conf")
@@ -248,6 +249,7 @@
 	no-run|dry-run
 	help|?
 	version
+	cow
 	)) or usage;
 
 chomp($$Options{Server} = `hostname`);
@@ -449,11 +451,31 @@
 scalar @{$$Options{exclude}}
 	and push @rsyncargs, '--exclude-from=' . $exl_file;
 
+# take full advantage of btrfs copy on write
+$$Options{cow} and (lc $$Options{cow} eq 'btrfs'
+	or seppuku 235, "Unsupported value for 'cow': $$Options{cow}");
+$$Options{cow}
+	and push @rsyncargs, '--inplace';
+
 if (!$$Options{'no-run'})
 {
 	mkdir "$vault/$image", 0700
 		or seppuku 230, "mkdir $vault/$image failed";
-	mkdir $destree, 0755;
+        # tree/ is a btrfs subvolume instead of a normal directory
+        if (lc $$Options{cow} eq 'btrfs')
+        {
+                if ($$Options{init})
+                {
+                        system("btrfs subvolume create $destree > /dev/null") == 0
+                                or seppuku 233, "creating btrfs volume at $vault/$image/tree failed";
+                } else {
+                        system("btrfs subvolume snapshot $reftree $destree > /dev/null") == 0
+                                or seppuku 234, "creating btrfs snapshot at $vault/$image/tree failed";
+                }
+        } else {
+                mkdir $destree, 0755;
+        }
+
 
 	open(SUMMARY, ">$vault/$image/summary")
 		or seppuku 231, "cannot create $vault/$image/summary"; 
@@ -475,7 +497,7 @@
        	Image image-temp Reference
 	Image-now Expire Expire-rule
 	exclude
-	rsync-option
+	rsync-option cow
 	Enabled
 );
 $summary_reset = 0;
@@ -509,7 +531,7 @@
 	printf SUMMARY "%s: %s\n", $key, $val;
 }
 
-$$Options{init} or push @rsyncargs, "--link-dest=$reftree";
+$$Options{init} or $$Options{cow} or push @rsyncargs, "--link-dest=$reftree";
 
 $rclient = undef;
 $$Options{client} ne $$Options{Server}
@@ -757,7 +779,12 @@
 
 if($status{fatal})
 {
-	system ("rm -rf $destree");
+        if (lc $$Options{cow} eq 'btrfs')
+        {
+                system ("btrfs subvolume delete $destree > /dev/null");
+        } else {
+                system ("rm -rf $destree");
+        }
 	unlink $err_temp;
 	printf SUMMARY "%s: %s\n", 'Status', $Status_msg;
 	exit 199;

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Dirvish mailing list
[email protected]
http://www.dirvish.org/mailman/listinfo/dirvish

Reply via email to