btrfish/bootstrap.fish

48 lines
1.0 KiB
Fish
Executable File

#!/usr/bin/fish
set scriptdir (dirname (status --current-filename))
source $scriptdir/config.fish
source $scriptdir/utils.fish
if test -d $subvoldir
echo "Warning: backup directory already exists."
echo "Existing subvolumes won't be overwritten."
else
echo "Creating subvolume directory..."
mkdir $subvoldir
end
echo "Creating initial 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 not test -d $safepath
if not test -f $mount/.btrfish-ignore
sudo btrfs subvolume snapshot -r $mount $safepath
set snapshots $snapshots $safepath
else
echo ".btrfish-ignore found in $mount, skipping..."
end
end
end
echo "Syncing..."
sync
echo "Sending to target..."
for snapshot in $snapshots
sudo btrfs send $snapshot | receive-on-target
while [ $status != 0 ]
echo "Sending failed, retrying..."
sleep 5
sudo btrfs send $snapshot | receive-on-target
end
end
echo "Done!"