Step 1) create a file:
sudo mcedit /root/daily_backup.sh
Write the following lines to file (try to put it without line break) :
rsync -a --delete --log-file=/data/backup/crontab_log/$(date +%Y%m%d)_rsync.log --exclude "/media" --exclude "/mnt" --exclude "/home" --exclude "/data" --exclude "/proc" --exclude "/lost+found" --exclude "/dev" --exclude "/sys" --exclude "/tmp" --exclude "/var/cache/apt/" --exclude "/cdrom" / /data/backup/crontab_ubuntu_backup
What does this command?
-a: means that copy file in archive mode, once the file is copied next time only the changes will be copied;
--delete: delete files from destination if they are deleted from source;
--log-file: where to put log file;
--exclude: exclude files matching the pattern;
/: source, in my case it is the root (/);
/data/backup/crontab_ubuntu_backup: destination;
Step 2) make file executable:
sudo chmod +x /root/daily_backup.sh
Step 3) create a cron job:
sudo crontab -e
Under the line "# m h dom mon dow command" start a new line and write:
1 2 * * * /root/daily_backup.sh
Once again what does it mean?
- 1: number of minutes;
- 2: number of hours (0-24);
- *: day of month;
- *: month;
- *: day of week;
- /root/daily_backup.sh: command to execute;
so I have created a job that executes every day at 02:01 h.
Take a look on the following sites for detailed description for the rsync and crontab command.
janos ujvari @October 21, 2008.