Skip to main content

Automatic Backups With Rsync and Crontab

·171 words·1 min
System-Administration Linux

So, first thing, is to install rsync, which of course requires admin or super user priviledges.

$ apt-get install rsync

With that done, one needs to create a backup script somewhere that will be run, so create a file somewhere.

$ nano backup.sh

Now, enter the command for the rsync backup, with the desired options.

0 0 * * * rsync -a /path/to/source /path/to/destination

Note that the first 5 characters determine the time when this script will run, whereas ‘rsync’ and on is the actual command. Make sure that the account that will run this script has access to both directories.

#Min | Hour | Day | Month | Day of Week | Run Command
 0 	   0 	    *      *         *         rsync -ar /sambadisk /backupdisk
# Set to run everyday at midnight.

Now, with the script setup and ready, one just needs to add it to the crontab (Command Run On Notice TABle).

$ crontab backup.sh

To check that it was added successfully, just enter “crontab -l” to list all running crons.