Everybody knows the importance of a daily back-up. There are a lot of tools with fancy GUIs and useless information but sometimes the best is to keep it simple.
Linux offers some very powerful build-in ways of creating a perfect backup.
The scope is to create a secure incremental automatic daily backup without using fancy tools.
STEP 1: Create a secure external back-up resource
The easiest way to have an external secure back-up resource is to buy a USB external hard disk and encrypt it with truecrypt (or a similar tool). They start to be very cheap, one is able to buy >1TB external disks at under $100.
Mine is mounted under /media/truecrypt2/ and is a true device encrypted external drive.
STEP 2: Create a back-up bash script using rsync
rsync is a very powerful tool to synchronize files between a source and a destination target (local target, remote target etc. ).
We define our script backup_cron.sh as:
#!/bin/bash
rsync -aAXv --stats /media/truecrypt1/* /media/truecrypt2/
Where we used the following parameters for the rsync command line:
-a = archive mode; equals -rlptgoD (no -H,-A,-X)
rsync will: recurse into directories, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner (super-user only), preserve device files (super-user only), preserve special files
–stats = give some file-transfer stats
/media/truecrypt1/* = the source directory, note that is very important to terminate with /* so that the whole content under this directory is copied
/media/truecrypt2/ = the destination directory, under which the external encrypted drive is mounted
Note that rsync is an incremental back-up like tool. It means that only the modified files will be copied the next time the command is executed, so only the changes done during the day are copied to the external drive.
STEP 2: Create a cron job to call everyday(work day) the back-up bash script
Create a file /etc/cron.d/backup to specify the back-up cron job
# Runs the backup job
10 20 * * mon,tue,wed,thu,fri root /root/backup_cron.sh >> /var/log/backup_cron.log
The job is defined such as on every working day of the week (mon,tue,wed,thu,fri) at 20:10 the backup_cron.sh script is executed as root and the output is written to /var/log/backup_cron.log
Make sure the cron service is started and set to autostart.
[paypal_donation_button]