From f8fd363aad4cc4b5a2924656e018861712ef9407 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Wed, 8 Jun 2016 16:38:21 +0000 Subject: [PATCH] Only keep one snapshot if .btrfish-keepone exists in the root of the subvolume --- backup.fish | 10 ++++++++-- utils.fish | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backup.fish b/backup.fish index 475a094..85c713f 100755 --- a/backup.fish +++ b/backup.fish @@ -51,11 +51,17 @@ end echo "Renaming subvolumes on target..." for pair in $pairs set subvol (clean-name (get-subvol $pair)) + set mount (get-mount $pair) + + if not test -f $mount/.btrfish-keepone + rename-target-subvolume $subvol $subvol.(date +%Y-%m-%d) + else + delete-target-subvolume $subvol + end - rename-target-subvolume $subvol $subvol.(date +%Y-%m-%d) rename-target-subvolume $subvol-new $subvol - sudo rm (get-mount $pair)/.btrfish-lock + sudo rm $mount/.btrfish-lock end echo "Done!" diff --git a/utils.fish b/utils.fish index e742b82..851aa22 100755 --- a/utils.fish +++ b/utils.fish @@ -12,6 +12,10 @@ function rename-target-subvolume ssh -i $sshkey $targetuser@$targethost mv -v $targetpath/$argv[1] $targetpath/$argv[2] end +function delete-target-subvolume + ssh -i $sshkey $targetuser@$targethost sudo btrfs subvolume delete $targetpath/$argv[1] +end + function get-subvol echo $argv | cut -d' ' -f1 end