Last active
May 22, 2021 13:02
-
-
Save ctsiaousis/b9b791dd831923a9dd7d6a9b100d9967 to your computer and use it in GitHub Desktop.
A simple script for automated `rsync` backups to encrypted devices. Called like `./backup.sh /dev/sde1 /myMountPoint/ myUserName`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
[[ $# -ne 3 ]] && echo "Please specify device, mount-point and username. Exiting..." && exit | |
[[ $EUID -ne 0 ]] && echo "Please run as root. Exiting..." && exit | |
[[ ! -d $2 ]] && echo "Argument 2 must be a directory. Exiting..." && exit | |
[[ `id $3 &>/dev/null || echo -1` -ne 0 ]] && echo "Not a valid user. Will not push cache to backup. Exiting..." | |
DIR=${2%/} #remove trailing dash | |
cryptsetup open $1 backup || { echo "Could not open \"backup\". Exiting..." ; exit; } #backup is the name of cryptsetup | |
mount -t ext4 /dev/mapper/backup $DIR || { echo "Could not mount \"/dev/mapper/backup\" to \"$DIR\". Exiting..." ; exit; } | |
sudo rsync -aAXv --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","$DIR/*","/home/$3/lost+found/*","/home/$3/.cache/*","/home/$3/.mozzila/*"} / $DIR && echo "rsync finished properly" || echo "rsync -- ERROR" | |
umount $DIR || { echo "Error while unmounting. Exiting..." ; exit; } | |
cryptsetup close backup || { echo "Error while closing \"backup\". Exiting..." ; exit; } | |
echo Finished and unmounted $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment