~/Copying remote files to local machine

21 June 2014

I recently bought a mac, and i prefer to my Windows machine, as I wasn’t a fan of Win8. As I don’t keep my databases within my central version control server, I had to manually copy them down from production, to my local machine (to complete my development environment set-up.)

To do this, I had to first get a backup of all my MySQL databases;

ssh user@server

cd /home/harrydenley/Backups/

mysqldump --all-databases -uroot -p > backup.sql

Now we’ve got a backup of all our MySQL databases, we’re going to want to copy them down into our local machine.

First, we need to create a SSH key on our local machine, and add it to ~/.ssh/authorised_keys on our remote server.

cd ~/.ssh

ssh-keygen -t rsa

cat id_rsa.pub

So now that we’ve generated our key on our local machine, we need our remote server to authorise it.

Log into your remote server (ssh user@server) and perform the following;

Now that our remote server has been configured, we can now copy the files to our local machine using scp.

On our local machine, we can run the following to copy our remote files down to our local machine;

scp -r user@server:/path/to/backup /Users/harrydenley/Desktop/

You will be prompted for your RSA key password (from when we generated it earlier), and once confirmed, the files will start to copy down to your local machine!