Heyho!

Now this is embarassing...  wrong assumptions and not enough testing 
resulted in dirvish-expire not working for btrfs trees. Sorry about that.

Fixed btrfs support attached.

As suggested, it would be sensible to rename the "btrfs" binary option into 
a "cow: btrfs" option, to allow future extension with support of other cow 
filesystems.  I don't have time for this right now though.

(And if anybody else is playing with btrfs: don't call btrfs defrag.  It 
currently expands cow files into separate copies, so your diskspace will 
probably explode. btrfs balance is fine.)

cheers
-- vbi

-- 
featured link: http://www.pool.ntp.org
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 ($$expire{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},
+                                btrfs   => $$summary{btrfs},
 				path	=> $path,
 			}
 		);
diff --git a/dirvish.conf.5 b/dirvish.conf.5
--- a/dirvish.conf.5
+++ b/dirvish.conf.5
@@ -177,6 +177,9 @@
 .Bi branch\-default: branch_name (S)
 Specify a default \*[branch] to use.
 .TP
+.Bi btrfs: (B)
+If true, use btrfs snapshots instead of hardlinked trees.
+.TP
 .Bi client: \*ousername@\*cclient_name (S)
 specify a client to back up.
 
diff --git a/dirvish.pl b/dirvish.pl
--- a/dirvish.pl
+++ b/dirvish.pl
@@ -93,6 +93,7 @@
 	whole-file
 	xdev
 	zxfer
+        btrfs
 );
 
 %RSYNC_OPT = (		# simple options
@@ -449,11 +450,29 @@
 scalar @{$$Options{exclude}}
 	and push @rsyncargs, '--exclude-from=' . $exl_file;
 
+# take full advantage of btrfs copy on write
+$$Options{btrfs}
+        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 ($$Options{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"; 
@@ -509,7 +528,7 @@
 	printf SUMMARY "%s: %s\n", $key, $val;
 }
 
-$$Options{init} or push @rsyncargs, "--link-dest=$reftree";
+$$Options{init} or $$Options{btrfs} or push @rsyncargs, "--link-dest=$reftree";
 
 $rclient = undef;
 $$Options{client} ne $$Options{Server}
@@ -757,7 +776,12 @@
 
 if($status{fatal})
 {
-	system ("rm -rf $destree");
+        if ($$Options{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