scripts/backupnaz.sh
2023-08-10 21:47:21 +02:00

40 lines
797 B
Bash
Executable file

#!/bin/sh
# Monthly backup script for my NAS
#set -e
DEVICE=/dev/sdb1
pass backups/disk | sudo /sbin/cryptsetup luksOpen $DEVICE backups "$@"
if grep /dev/mapper/backups /proc/mounts >/dev/null
then
echo "external drive ($DEVICE) seems to be mounted. good."
else
if sudo mount /dev/mapper/backups /mnt/backups/
then
echo " * external drive ($DEVICE) successfuly mounted."
else
echo " * FATAL: unable to mount"
exit 1
fi
fi
for slot in public private
do
echo
echo " * backing up $slot"
echo
time ionice -c 2 rsync --rsh='ssh -q -o RemoteCommand=none' --info=progress2 -av --delete --exclude-from ~/.backup_excludes naz:/nfs/$slot/ /mnt/backups/$slot/
done
echo
echo " * unmounting"
echo
sleep 2
sync
sudo umount /dev/mapper/backups
sudo dmsetup remove /dev/mapper/backups