Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Ubuntu server hosted on Amazon EC2. I need to create an automated backup scheme so I created another Ubuntu instance on my local network which is hosted in a virtual environment.

I managed to transfer the necessary files between 2 machines on the same network using the rsync command:

rsync -azvv -e ssh /home/path/folder1/ remoteuser@remotehost.remotedomain:/home/path/folder2

How can I do the same thing but transferring files from my Amazon server to my local server? Is there a way I can achieve this with port forwarding, or by VPN, or anything else?

It doesn't have to be rsync. If you know about a better method, kindly let me know.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Just swap both locations:

rsync PARAMETER REMOTE LOCAL

so in your case the following should do the job:

rsync -azvv -e ssh remoteuser@remotehost.remotedomain:/home/path/folder2 /home/path/folder1/
share|improve this answer
    
So are you saying that I should connect from my local machine terminal to my remote machine? Makes sense. The thing is that my local machine uses password authentication while the remote uses public key. Therefore when I connect from my local machine, it asks for the password of the remote machine, which it does not has. How can I bypass this? –  seedeg Jun 28 '11 at 11:48
    
According to your command rsync [...] remoteuser@remotehost.remotedomain:[...] you should be able to connect to remotehost via ssh!? My command just connects with the same account at the same host, so why should it fail? Please run both commands from the same machine. Sine you are not explicitely connecting to your local machine you don't need the password for the local host. –  binfalse Jun 28 '11 at 11:56
    
What I did was I added my public key code of the amazon server to the authorized_hosts of the local server and there is no need for a password –  seedeg Jun 30 '11 at 7:11
add comment

So you want to setup an automated backup between your local server and an amazon hosted server?

  1. Configure the ssh keys between your local server and your amazon server.

    foo@local-server $ ssh-keygen
    foo@local-server $ scp ~/.ssh/id_rsa.pub amazon-server:~/id_rsa.pub
    foo@amazon-server $ cat ~/id_rsa.pub >> .ssh/authorized_keys
    

    You should be able to ssh from the local server to the remote server without needing a password. Make sure the permissions on the .ssh directory and authorized_keys file are 700 and 600 respectively.

  2. Run your rsync command from your local server

    foo@local-server $ rsync -azvv amazon-server:folder2 ~/folder1/
    
  3. You'll probably want to set this up as a cronjob running from your local server

    foo@local-server $ crontab -e
    

    Add something like the following to your crontab. This will run the backup at midnight every night.

    * 0 * * *  rsync -azvv amazon-server:folder2 ~/folder1/
    
share|improve this answer
1  
have a look at ssh-copy-id to make the copy of ssh keys. –  Johan Jun 28 '11 at 20:30
    
That's exactly what I did. –  seedeg Jun 30 '11 at 7:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.