Using SSH and SCP you can copy your remote web VPS backups to your local machine in a secure manner and then by creating a back up script you can either run the script adhoc or schedule the process with a user launch agent.
The first step is to create a SSH passwordless connection between the vps webserver and the local machine, this is done by adding the public SSH key of the local computer to the ‘authorised_keys’ file of the remote VPS host.
Once this is done you can SSH into your remote VPS host without a password prompt.
Test that the connection works with no password
local:~ user$ ssh firstname.lastname@example.org Last login: Mon Jul 18 12:58:53 2011 from 12.34.567.890 root@hosting [~]# exit
Once the connectionless communication is established you can use ‘scp’ to securely copy your backup to your local machine, ‘scp’ runs in the ‘ssh’ protocol so the connection is encrypted. Find out the path from your web host where the backups are filed. In this example they are at the root level ‘/backups’.
So to copy over the archived backups the command below will recursively copy the ‘/backups’ directory on the remote host to the local users desktop directory.
local:~ user$ scp -R email@example.com:/backups ~/Desktop
The first part of this command is the ‘from’ directory and since it is the remote host, the ssh connection string is used separated by a ‘:’ then the remote path and the second part of the command is the ‘to’ directory which is our desktop folder on our local host.
Once you have tested and verified that the copy is made sucessfully , it’s worthwhile make a simple script that you can run adhoc.
Create a script using your from and to destinations and and save it as ‘backup.sh’:
#!/bin/bash scp -R firstname.lastname@example.org:/backups ~/Desktop
Save it in /usr/sbin and give it the ownership and permissions of the below
-rwxr-xr-x 1 root wheel 269B Jul 14 10:15 backup.sh
Reload the shell to apply the new command:
Then run the command from the command line
local:~ user$ backup.sh
One final thing to do is to schedule the script to run at a frequency – you can create a launch agent in your home library and set that to run weekly or monthly.