PDA

View Full Version : Automatize backup with rsync and crontab with date command



Fli
03-24-2015, 07:15 PM
If you got little backup to do and want to have a backup every night with the date, you can do the following:

Create a script:

vi /root/rsync.sh

Now put that in your script:

folder=`date +%Y_%m_%d`
rsync -avH /folder/to/backup /backup/$folder >> /var/log/rsync/acc

Then put your script executable:

chmod +x rsync.sh

or

chmod 755 rsync.sh

Create the folder rsync in /var/log:

mkdir /var/log/rsync

Add the script to your crontab (Crontab syntax: http://geekzine.org/2007/09/28/crontab/):

crontab -e

# m h dom mon dow command
0 4 * * * /root/rsync.sh

Save the file and you’re done!