Automatically Backing up a USB Drive with RSYNC (KDE)
Published:
| by Julian Knight Reading time ~2 min.
📖 Posts
| 📎
Development, Linux
| 🔖
Backup, BASH, Batch, Scripting, USB
USB Drives of all kinds need to be backed up and the best backup is an automatic one (it’s the only way to make sure that it gets done!).
So here is one recipe for doing just that using RSYNC and some BASH scripting magic.
I’ve split this into two files. You don’t have to do this of course and one may well be better for you. I used two because I can run the second one manually as well. Put everything in autorun.sh if you want to backup each drive individually, however, note that KDE produces an annoying extra dialog (a security warning) asking if you really want to run the autorun.
autorun.sh
This resides in the root of the USB drive and is executed automatically by KDE when the drive is detected (though not if the drive is attached when booting)
usb-backup-manual.sh
This is a bit of a nasty hack, I have manually configured a list of drives that might be attached so that I can back them all up together. Not elegant but it works for me.
autorun.sh 🔗︎
Note the use of KDialog to provide a minimal GUI. In the second file, KDialog produces a progress bar.
Also note the RSYNC parameters. These are always painful to get to grips with so it is nice to have an example to work from. In this case I am backing up so I am making sure that the backup is an exact copy of the original (as opposed to synchronising which would allow changes to happen on either side).