Script to backup home directory.

My laptop is in it’s final stages. It might die any moment. And since I’ve spent almost three years moulding my Arch install on it to my liking, I spent many sleepless nights pondering about what I’d do if it crashed and never woke up.

Earlier I wrote a blog post on how to transfer an existing Arch install onto a new laptop. In that blog post, I noted that in essence, it is the home directory and the list of packages of an Arch install which uniquely determines it and so if I had a copy of these, in theory, I would be able to transfer my install onto any new laptop. The steps to do this were outlined in that post.

So the question remained on automating this process. To acheive that, I wrote a simple bash script.


echo "Backing up to HDD..."
# Use rsync to backup to external HDD.
sudo rsync --info=progress2 -aAXn --delete --exclude={/home/*/.thumbnails/*,/home/*/.cache/mozilla/*,/home/*/.local/share/Trash/*} /home/kody/ /run/media/kody/TOSHIBA\ EXT/ARCH-BACKUP-2017/
echo "Back up done."
# Make a list of packages and store them in files on the HDD.
echo "Making a list of AUR and Pacman Packages and storing it on the HDD..."
pacman -Qqe | grep -vx "$(pacman -Qqm)" > /run/media/kody/TOSHIBA\ EXT/ARCH-BACKUP-2017/Packages_$(date '+%Y-%m-%d')

pacman -Qqm > /run/media/kody/TOSHIBA\ EXT/ARCH-BACKUP-2017/Packages_AUR_$(date '+%Y-%m-%d')

echo "Done."

Adding the ‘n’ option in rsync does a dry run first so you can see if things are okay before going in for the kill.