This just sync any folder with an external device by using crontab. It's meant to run sparsely, hence it mounts and unmounts the device on every execution.
It consists of two scripts:
with_device.sh
: mounts and umounts the external device - should be in a folder with restricted accesssimple_backup.sh
: does the actual backup using rsync - can be in any folder
Crontab sample:
# Root's crontab (sudo crontab -e)
#
# Runs every day at 4am.
#
# m h dom mon dow command
0 4 * * * /root/scripts/with_device.sh <DEVICE_UUID> <USER> /home/<USER>/scripts/simple_backup.sh <SOURCE_DIR> [TARGET_SUBDIR]
- Both scripts must be marked as executable (
chmod +x
) - Because mounting requires superuser privileges, the task should be in root's crontab:
sudo crontab -e
- A log file is generated per execution with the same name as the backup script (e.g.
simple_backup.log
) - no appending - The mounting point is hidden in the same folder as the backup script with template:
.tmp-mnt-<DEVICE_UUID>
- this folder will be unmounted and deleted after the execution - Since
with_device.sh
runs with root privileges, you should prevent non-root users from editing it - Make sure your user have write permissions on the external device
- Get device's
UUID
:sudo blkid /dev/sdX