How To Take Secure Remote Backups Using SSH

A couple of weeks back Damien posted an excellent tutorial on securing your internet connection using SSH. In his post, he explains what SSH is as well as the SSH Tunneling method that he uses to secure the internet traffic.

Today, I’ll be taking you through another tutorial that involves using SSH to take backups of your remote servers.

As you guys might be aware that I also run a website called Geeky Ninja which is hosted by the nice folks over at Dreamhost on a Linux server.

Even though Dreamhost keeps a backup of my site, as a webmaster I’m a little paranoid about backups and worry about losing my data all the time. That is why I also backup my site to a remote location occasionally. And this is where SSH comes in.

As you guy probably know that SSH is a secure encrypted protocol to communicate between two machines. Since SSH is not a text based protocol like telnet, it is possible to transfer actually binary files using this protocol and SCP is the utility that accomplishes this task on Unix/Linux based systems. SCP encrypts the files given to it using the SSH protocol and copies it to the remote destination that the user specifies.

Getting Started

First of all you need to make sure that the remote system that you want to copy the data from has ssh installed and running. In my case, that’s the remote webserver hosted at Dreamhost.

Login to the remote system and issue the “pwd” command to see your current directory.

scp-001

Note down the path that pwd prints. Now, from your local system issue the following scp command.

scp-002

Replace:
username with your real username on the remote system,
Remote_IP with the IP Address/Name of the remote system,
Remote_directory with the output of the pwd command from above and
backup_directory with the name of the directory on your local system where you want to store the backups.

That’s it. This command will copy all the files and directories under the remote_directory to the backup_directory on your local system.

Backing Up in Windows

The above instructions will work well for Unix/Linux based machines, but what if you use Windows as your desktop and want to make a backup of your data from the remote machine to your windows desktop ?

Well, in that case you can just use the excellent utility, WinSCP which is a graphical SCP client for Windows

WinSCP

WinSCP gives you the familiar Explorer like interface with full support for drag and drop. Just browse through the directory you want to backup on the right pane and drag it over to the left pane and say GoodBye to text only unsecure FTP sessions.

How do you guys backup your remote servers ? Let us know in the comments.

Image Credit: Carbonnyc