Home Forums Get Help for Klok How do I backup my data – Linux Reply To: How do I backup my data – Linux


Automate backup

You may want to automate backup so you don’t have to add it to your calendar. It will actually be easier to automate the backup then create a calendar entry.

I tend to keep things simple and easy, so I can show new users how easy it is to do such things under Linux. The solution that I use for automation is ‘crontab’. It’s simple, lightweight and does the job well. With Crontab I can configure when I want to run the rsync command: daily, weekly, monthly, or more than once a day (which I won’t do). I have configured mine to run at 11:30 p.m. every day after work so all of the files that I worked on throughout the day get synced.

Depending on your distro you may have to install a package to get crontab on your system. If you are on Arch Linux, for example, you can install ‘cronie’. You can choose the default editor for crontab; I prefer nano. Run this command and replace ‘nano’ with the desired editor.

export EDITOR=nano
Now run ‘crontab -e’ to create cron jobs. It will open an empty file where you can configure the command that you want to run at a desired time. (See image, above.)

The format of crontab is simple; it has five fields followed by the command:

m h dm m dw command
Here m stands for minutes (0-59); h for hour (0-23); dm for day of the month (1-31); m for month (1-12); and dw for day of the week (0-6 where 0 is Sunday). The format is numerical and you have to use ‘*’ to commend the fields that you don’t want to use.

I run the command every day at 11.30 so the format will be

30 23 * * * rsync -av –delete /media/hdd1/data-1/ /media/hdd2/data-2/
If you want to run rsync only once a month then you can do something like this:

30 23 1 * * rsync -av –delete /media/hdd1/data-1/ /media/hdd2/data-2/
Now it will run at 11:30 p.m. on 1st of every month. If you don’t want it to run every month than you can configure it to run every six months:

30 23 1 6 * rsync -av –delete /media/hdd1/data-1/ /media/hdd2/data-2/
That will make it run every year on June 1. If you want to run more than one command, then create a new line for every command. Rsync is not the only command you can automate with ‘crontab’ you can run ‘any’ command using it.

As you can see both tools – rsync and crontab – are extremely simple and lightweight yet extremely powerful and highly configurable. Linux doesn’t have to to complicated!