Remote server rsync using cron
I have two servers, and I'm wanting to set up a cron job to backup contents from one server to the other. I'm writing my own thing because I only want to copy certain directories, instead of the whole account (the whole account is huge, and most of it doesn't need a continuous backup).
If I were doing it manually, I would use this while logged in to the backup server:
But in practice, this prompts for a password, which I don't think I can submit in a cron. So how can I do the same thing as a cron?
rsync -aupog -e 'ssh -p 1234' root@123.45.67.89:/home/example/public_html/directory/ /backup/directory/
But in practice, this prompts for a password, which I don't think I can submit in a cron. So how can I do the same thing as a cron?
-
You will have to create a public/private key without a passphrase. Then you will need to specify the key on your rsync command. example: rsync -aupog -e 'ssh -p 1234 [COLOR="#FF0000">-i /root/.ssh/yourkey' root@123.45.67.89:/home/example/public_html/directory/ /backup/directory/
Here's a guide to create the key : [url=http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/]3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id0 -
Thanks, that worked! I had to do a little bit of research on how to create the public/private key and copy it to the server with a different port, and in digging I found that it was a little easier than the article said. All I really had to do was, from the backup server: ssh-keygen -> Enter, Enter, Enter (blank on all 3) ssh-copy-id "root@123.45.67.89 -p 1234" (where 1234 is the port) Then, the rsync was the same code as before, I just didn't have the prompt for the password. I didn't need to include the '-i /root/.ssh/yourkey' section, for whatever reason (maybe because I left the first prompt blank after ssh-keygen?). Thanks again for pointing me in the right direction, InterServed! That helped a lot. 0 -
You're more than welcome and yes I'm aware that it works without specifying the key, it's just how i normally do it. For me it's better to have a clearer understanding of the code so i know exactly what key is being used and so on. You can also generate/edit a key from WHM -> Security Center -> Manage root's SSH Keys 0 -
I am happy to see the solution that InterServed provided to you was helpful. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
4 comments