The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Remote server rsync using cron

Discussion in 'General Discussion' started by GoWilkes, Mar 10, 2014.

  1. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    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' 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?
     
  2. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    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:
    Code:
    rsync -aupog -e 'ssh -p 1234 [COLOR="#FF0000"]-i /root/.ssh/yourkey[/COLOR]' root@123.45.67.89:/home/example/public_html/directory/ /backup/directory/
    Here's a guide to create the key :
    3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
     
  3. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    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 "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.
     
  4. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    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
     
    #4 InterServed, Mar 11, 2014
    Last edited: Mar 11, 2014
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page