Backup Flash Drive

Using the popular backup program rsyn, I have written two very short scrips that will backup my flash drive each time it is unmounted from my computer.

The first script that I wrote needs to be on the flash drive.  Open your favorite text editor and copy the three lines. 

TAR_DIR='/home/username/backup/'
rsync -a /media/disk/ --delete $TAR_DIR
read -p "Press Any Key to Continue . . ." cd

Explanation:  In the first line, edit the path to the directory that you would like to back up the flash drive.  The second line runs rsync, check the man on rsync to add/remove any flags to your preference by running "man rsync".  The last line just stops the script to show any errors were encountered.  Save the script to the root directory in your flash drive.  The root directory varies between distros.  In Ubuntu is it located in /media/disk/.  Give the filename .umount.  (Note: Keep the period before umount, this way it is hidden)

The second script is on the computer that the flash drive is plugged into.  In the first line if runs the script from above.  The second line unmounts the flash drive.  And the third line stops the script to show any errors and the tell you that the script has finished.  Save this file to .umount in your home directory.

/media/disk/.umount
sudo umount /media/disk
read -p "Finished umount . . ." cd

Once both scripts are written I made a launcher on one of my gnome pannels by right clicking where I wanted it and choosing "Custom Application Launcher".  In this menu I choose type to be "Application in Terminal" and comman "/home/user/.umount.  Name and comment can be anything to remind yourself what this launcher is.

Now that the launcher is created just click on it from the gnome pannel and it will copy all your files to the target directory and unmount the drive.  It may need to ask for you password to run umount.  The first time this is run it will take longer since it is copying everything over, but after that it should be quick.

If you have multiple flash drives you can add the first script to the flash drives root directory, but with a different target directory.