Auto backup on mount

Created: — modified: — tags: bash

Automatically backup files on media mount, using usbmount

Assuming you're using WM, not DE, you probably have installed usbmount package in order to automatically mount USB sticks and HDDs when they are inserted.

It has nice "autorun" feature which we can use to automatically backup onto some removable harddisks when they are inserted. Assuming you're familiar with my rsync backups script (if not, you always can write your own or use plain rsync).

Simply put this script into /etc/usbmount/mount.d/:


test -d $ROOT || exit 0

export IGNORE_23=1

/root/ /home/ $ROOT/`hostname`


Now, if inserted drive has dir with a subdir matching your machine's hostname, it will be used to keep incremental backups of your home dirs. Remember to remove ALLOW_FIRST_RUN=1 when it's not needed anymore.

Few notes regarding speed optimisation: