mauville: added sanity checks to backup script

This commit is contained in:
Aly Raffauf 2024-06-08 14:56:25 -04:00
parent dea16e6f64
commit 0b5bab79d3

View file

@ -78,14 +78,23 @@
}; };
Service = { Service = {
ExecStart = "${pkgs.writeShellScript "backblaze-sync" '' ExecStart = "${pkgs.writeShellScript "backblaze-sync" ''
BACKBLAZE=${lib.getExe pkgs.backblaze-b2} declare -A backups
backups=(
$BACKBLAZE sync --delete /mnt/Media/Music b2://aly-music ['/home/aly/pics/camera']="b2://aly-camera"
$BACKBLAZE sync --delete /mnt/Media/Audiobooks b2://aly-audiobooks ['/home/aly/sync']="b2://aly-sync"
$BACKBLAZE sync --delete /mnt/Archive/Archive b2://aly-archive ['/mnt/Archive/Archive']="b2://aly-archive"
['/mnt/Media/Audiobooks']="b2://aly-audiobooks"
$BACKBLAZE sync --delete /home/aly/sync b2://aly-sync ['/mnt/Media/Music']="b2://aly-music"
$BACKBLAZE sync --delete /home/aly/pics/camera b2://aly-camera )
# Recursively backup folders to B2 with sanity checks.
for folder in "''${!backups[@]}"; do
if [ -d "$folder" ] && [ "$(ls -A "$folder")" ]; then
${lib.getExe pkgs.backblaze-b2} sync --delete $folder ''${backups[$folder]}
else
echo "$folder does not exist or is empty."
exit 1
fi
done
''}"; ''}";
}; };
}; };