btrfish/backup.fish

55 lines
1.2 KiB
Fish
Raw Normal View History

2016-05-05 03:48:13 +02:00
#!/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
if test -d $safepath
sudo btrfs subvolume snapshot -r $mount $safepath-new
2016-05-05 03:48:13 +02:00
set snapshots $snapshots $safepath
else
echo $mount "is not bootstrapped and will not be included in the backups!"
end
2016-05-05 03:48:13 +02:00
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))
if test -d $subvoldir/$subvol
rename-target-subvolume $subvol $subvol.(date +%Y-%m-%d)
rename-target-subvolume $subvol-new $subvol
end
2016-05-05 03:48:13 +02:00
end
echo "Done!"