GoWilkes

Well-Known Member
Sep 26, 2006
692
33
178
cPanel Access Level
Root Administrator
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:

Code:
rsync -aupog -e 'ssh -p 1234' [email protected]:/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?
 

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider

GoWilkes

Well-Known Member
Sep 26, 2006
692
33
178
cPanel Access Level
Root Administrator
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 "[email protected] -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.
 

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider
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
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
I am happy to see the solution that InterServed provided to you was helpful. Thank you for updating us with the outcome.