scripts/sync-backup

40 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2022-12-26 14:20:37 +01:00
#!/bin/env bash
set -euo pipefail
read -sp "Password: " password
# get the drive path
drive="$1"
printf '\n%s\n\n' "Opening encrypted drive"
# open the encrypted drive
sudo cryptsetup luksOpen $drive luks
printf '\n%s\n\n' "Mounting encrypted drive"
# check if the /mnt/encrypted directory exists if not create it
[ -d "/mnt/encrypted/" ] || printf '%s\n' "$password" | sudo -S mkdir -p /mnt/encrypted
# mount the decrypted drive to /mnt/encrypted/ directory
printf '%s\n' "$password" | sudo -S mount /dev/mapper/luks /mnt/encrypted
# Here comes the fun part
# Using a list to backup all my shit
while read Line; do
2023-01-09 21:52:31 +01:00
echo "Syncing $(basename $Line)"
2023-02-22 19:17:52 +01:00
rsync -ahAX -v --delete "$Line" /mnt/encrypted
2022-12-26 14:20:37 +01:00
done <<< "$(cat $HOME/.config/rsync/backup-list)"
printf '\n%s\n\n' "Unmounting encrypted drive"
# unmount the decrypted drive and close/encypt it again
printf '%s\n' "$password" | sudo -S umount /dev/mapper/luks
printf '\n%s\n\n' "Closing encrypted drive"
printf '%s\n' "$password" | sudo -S cryptsetup luksClose luks