#!/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!"