#!/bin/bash # vim:ft=sh # New line separated list of all directories to backup read -d '' DIRS <<-"_EOF_" /etc /home /home_hdd _EOF_ # Path where backup will be mounted MPATH=/media/backup-hdd # UUID of disk UUID=b162ea95-38bb-42c6-b36a-1be98c65392c # If disk is encrypted CRYPT=true #################################################################### # Check if running as root if [ `id -u` -ne "0" ]; then echo Please run this as root. exit 1 fi # Mount disk PART=$(lsblk -fpl | grep "$UUID" | awk '{print $1}') if [ -z "$PART" ]; then echo Disk not detected. Exiting exit -1 fi if $CRYPT; then cryptsetup open "$PART" backup_enc || (echo Decryption failed && exit 1) PART=/dev/mapper/backup_enc fi mkdir -p "$MPATH" mount "$PART" "$MPATH" || (echo Mount failed && exit 2) # Do backup while read -r DIR; do echo Backing up: $DIR rdiff-backup -b --exclude-device-files --exclude-fifos --exclude-sockets \ --terminal-verbosity=5 --print-statistics --exclude-other-filesystems \ "$DIR" "$MPATH/$(basename $DIR)/" rdiff-backup --remove-older-than 100D --force \ --terminal-verbosity=5 --print-statistics \ "$MPATH/$(basename $DIR)/" done <<< "$DIRS" # Unmount disk sync umount "$MPATH" || (echo Unmount failed. Unmount by hand. && exit 3) if $CRYPT; then cryptsetup close backup_enc fi # Store when we did last backup and update i3blocks status date +"%s" > /home/cynerd/.backup_date pkill -RTMIN+13 i3blocks echo echo Backup finished