I wanted to backup my “home” folder in my newly installed Linux Mint installation to an external hard drive. The advantage of doing this is the connections to my NAS is also linked to my external drive so it will backup my important NAS folders as well as my local home folder.
I know there is a backup utility in Linux Mint that can backup my home folder but I wanted to geek out a bit so I tried to write a script to do this for me. I also wanted to make sure that script would alert me if the hard drive was not plugged in when I ran the script.
After a bit of messing and searching the internet (after all although I have a few degrees in computers and 20+ years experience in the IT field, I have never used Linux as a operating system, all my experience is in Mac OSX and Windows.) I found a way to see if an hard drive is connected to the system.
if [ ! -d /media/john/Backup ]; then
echo "Plug In The External Hard Drive Dummy ! !" ; exit 1
This part of the script checks to see if the media is located in “/media/john/” The hard drive is called Backup.
If it finds the hard drive it continues with the script, if not it posts the “Plug in the external hard drive dummy ! !” text
The command I used to copy the info over is “rsync”, which I am familiar with thanks to my Mac OS X days, though I had to brush up a bit on it since it was a few years since I used it (more like 5+ years)
This is what I have come up with:-
echo "Starting Backup of Home to External Hard Drive"
sudo rsync -av --delete --update --progress --exclude ".*/" /home/ /media/john/Backup/
-- All Backed Up --
What this part of the script does is look under my home directory and copies all the contents excluding the hidden folders to /media/john/Backup which is the external hard drive. If I have deleted a file in my home directory it will also delete it on my external hard drive.
Hope this helps someone out there.