1

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.

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

1 Answer 1

3

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 [email protected]

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

~# ssh [email protected]

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 [email protected]:/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.

0

You must log in to answer this question.