0

I have a server that holds all my backups and I would like to back them up to another server. I was just wondering the best way to do this.

do I setup rsync or use scp? I would also like to keep everything secure and use ssh if possible.

I keep the files under /home/servername/daily

Tom O'Connor
  • 27,440
  • 10
  • 72
  • 148
user158303
  • 11
  • 3
  • 1
    possible duplicate http://serverfault.com/questions/255084/simple-rsync-in-crontab-without-password – user9517 Feb 10 '13 at 09:12

2 Answers2

5

I would recommend using rsync+ssh for security reasons. You can use either pull or push backup. For instance, if you decide to use pull based backup, first generate ssh key on the remote server. You will then pull the files to the remote server from the original backup server.

  1. Remote('another') server: generate private/public key

    ssh-keygen -t rsa -b 2048
    

    Take the public key generated, say /root/.ssh/id_rsa.pub, to the Backup server.

  2. Backup server - add public key of remote server to the authorized_keys of the backup server.

     cat id_rsa.pub >> /root/.ssh/authorized_keys
    
  3. Remote server -Test public key ssh connection

     ssh -i /root/.ssh/id_rsa root@backupserver-hostname
    

    Add the following command to your crontab

    rsync -avz -e "ssh -i /root/.ssh/id_rsa" root@backupserver:/backupdir /thisdir
    

You can change the username, hostnames, private/public key file names, directories etc. based on your setup.

Daniel t.
  • 9,061
  • 1
  • 32
  • 36
3

crontab:

0 0 * * * rsync -av /home/servername/daily otherserver:/home/servername/dailyreplica

Midnightly crontab to rsync between the two servers.

Requires the root's (or whomever the crontab runs as)'s ssh key putting in the remote host's /home/$user/.ssh/authorized_keys file

Tom O'Connor
  • 27,440
  • 10
  • 72
  • 148