Linux cron: want to backup a folder

backupcron

I would like to backup a folder using cron on a centos. The folder c2duo_mms is located in /usr/local/src/djcode/c2duo_mms. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh.

Best Answer

A good thing to do would be to create a new compressed archive in your home.

Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:

#!/bin/bash

cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms

Be sure to add the executable permission to the script:

chmod +x /home/sh/c2duo_mms_backup.sh

Then add the relevant crontab entry with the crontab -e command:

0 13 * * 2 /home/sh/c2duo_mms_backup.sh

The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:

c2duo_mms_20110719.tar.gz 
Related Question