Implement backup script
This commit is contained in:
parent
49a6c0e0ae
commit
d5a105f3f2
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/fish
|
||||||
|
|
||||||
|
set scriptdir (dirname (status --current-filename))
|
||||||
|
|
||||||
|
source $scriptdir/config.fish
|
||||||
|
source $scriptdir/utils.fish
|
||||||
|
|
||||||
|
if not test -d $subvoldir
|
||||||
|
echo "Backup directory doesn't exist, run bootstrap.fish first!"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Creating new snapshots..."
|
||||||
|
for pair in (get-subvol-mounts)
|
||||||
|
set subvol (get-subvol $pair)
|
||||||
|
set mount (get-mount $pair)
|
||||||
|
|
||||||
|
set safename (clean-name $subvol)
|
||||||
|
set safepath $subvoldir/$safename
|
||||||
|
|
||||||
|
sudo btrfs subvolume snapshot -r $mount $safepath-new
|
||||||
|
|
||||||
|
set snapshots $snapshots $safepath
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Syncing..."
|
||||||
|
sync
|
||||||
|
|
||||||
|
echo "Sending to target..."
|
||||||
|
for snapshot in $snapshots
|
||||||
|
sudo btrfs send -p $snapshot $snapshot-new | receive-on-target
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Replacing old snapshots..."
|
||||||
|
for snapshot in $snapshots
|
||||||
|
sudo btrfs subvolume delete $snapshot
|
||||||
|
sudo mv $snapshot-new $snapshot
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Renaming subvolumes on target..."
|
||||||
|
for pair in (get-subvol-mounts)
|
||||||
|
set subvol (clean-name (get-subvol $pair))
|
||||||
|
|
||||||
|
rename-target-subvolume $subvol $subvol.(date +%Y-%m-%d)
|
||||||
|
rename-target-subvolume $subvol-new $subvol
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Done!"
|
|
@ -9,6 +9,10 @@ function receive-on-target
|
||||||
ssh -i $sshkey $targetuser@$targethost sudo btrfs receive $targetpath
|
ssh -i $sshkey $targetuser@$targethost sudo btrfs receive $targetpath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rename-target-subvolume
|
||||||
|
ssh -i $sshkey $targetuser@$targethost mv $targetpath/$argv[1] $targetpath/$argv[2]
|
||||||
|
end
|
||||||
|
|
||||||
function get-subvol
|
function get-subvol
|
||||||
echo $argv | cut -d' ' -f1
|
echo $argv | cut -d' ' -f1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue