2016-05-05 01:03:24 +02:00
|
|
|
#!/usr/bin/fish
|
|
|
|
|
2017-03-03 23:16:06 +01:00
|
|
|
set scriptdir (dirname (status --current-filename))
|
2016-05-05 01:03:24 +02:00
|
|
|
|
|
|
|
source $scriptdir/config.fish
|
2016-05-05 01:15:35 +02:00
|
|
|
source $scriptdir/utils.fish
|
2016-05-05 01:03:24 +02:00
|
|
|
|
|
|
|
if test -d $subvoldir
|
2016-05-24 00:02:53 +02:00
|
|
|
echo "Warning: backup directory already exists."
|
|
|
|
echo "Existing subvolumes won't be overwritten."
|
|
|
|
else
|
|
|
|
echo "Creating subvolume directory..."
|
|
|
|
mkdir $subvoldir
|
2016-05-05 01:03:24 +02:00
|
|
|
end
|
|
|
|
|
2016-05-05 02:04:21 +02:00
|
|
|
echo "Creating initial snapshots..."
|
|
|
|
for pair in (get-subvol-mounts)
|
|
|
|
set subvol (get-subvol $pair)
|
|
|
|
set mount (get-mount $pair)
|
|
|
|
|
2016-05-05 01:15:35 +02:00
|
|
|
set safename (clean-name $subvol)
|
2016-05-05 02:04:21 +02:00
|
|
|
set safepath $subvoldir/$safename
|
|
|
|
|
2016-05-24 00:02:53 +02:00
|
|
|
if not test -d $safepath
|
2016-06-05 07:33:37 +02:00
|
|
|
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
|
2016-05-24 00:02:53 +02:00
|
|
|
end
|
2016-05-05 01:03:24 +02:00
|
|
|
end
|
2016-05-05 02:05:14 +02:00
|
|
|
|
|
|
|
echo "Syncing..."
|
|
|
|
sync
|
2016-05-05 02:52:02 +02:00
|
|
|
|
|
|
|
echo "Sending to target..."
|
|
|
|
for snapshot in $snapshots
|
|
|
|
sudo btrfs send $snapshot | receive-on-target
|
2017-03-03 23:16:06 +01:00
|
|
|
while [ $status != 0 ]
|
|
|
|
echo "Sending failed, retrying..."
|
|
|
|
sleep 5
|
|
|
|
sudo btrfs send $snapshot | receive-on-target
|
|
|
|
end
|
2016-05-05 02:52:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
echo "Done!"
|