Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Because all my work is stored on a remote server I would like to auto backup my server monthly and weekly. My server is running Centos 5.5 and while searching the web I'm found a tool named rsync. I got my first update manually by using this command in terminal:

sudo rsync -chavzP --stats USERNAME@IPADDRES: PATH_TO_BACKUP LOCAL_PATH_TO_BACKUP

I then prompt my password for that user and bob's my uncle.

This backups the necessary files from my remote server to my local device but does somebody know how I can automate this? Like automatic running this script every sunday?

EDIT

I forgot to mention that I let direct admin backup the files I need and then copy those files from the remote server to a local server.

share|improve this question

migrated from serverfault.com Jul 2 '13 at 12:49

This question came from our site for professional system and network administrators.

2  
That's what cron is for. –  Jenny D Jul 1 '13 at 13:19

1 Answer 1

up vote 2 down vote accepted

I assume you backup from the remote server to a local machine that is always up and reachable.

First set up public key authentication with your server. In your remote server do

~# ssh-keygen 

accept the default and don't type the any password, so that the key will work passwordless. Then do

~# ssh-copy-id user@yourlocalmachine.example.com

and give the local server user password. Test it with:

~# ssh user@yourlocalmachine.example.com

You should log in passwordless.

After that, in your remote server, add a cron job executing the appropriate rsync commands. For example:

~# vim /etc/cron.daily/backup

#!/bin/sh
rsync -avq /sourcedir1 /sourcedir2 user@yourlocalmachine.example.com:/destinationdir

~# chmod 755 /etc/cron.daily/backup

Test the command first on a live shell without the -q flag to check that everything works. The cron job will run every night. You can put a similar script in /etc/cron.weekly and so on.

You can revert the whole process and set up the script/cronjob on your local machine, depending on your situation.

share|improve this answer
    
thanks for that. Great answer –  Mark Molina Jul 1 '13 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.