Follow these steps to setup a decent backup solution for your MT hosting (you can adapt this to any other hosting that offers SSH and RSYNC access).
First you'll want your linux box to be able to SSH into your hosting without a password using a SSH key instead.
Then, just clone the following repository somewhere in your linux box
Customize the file:
Next, make sure the variables in
match your enviroment.
Then you just need to run:
For extra peace of mind, set it to run from a cron job.
To save some typing you can create aliases to the servers you frequently access via ssh. This can be accomplished by either editing the global file ( /etc/ssh/ssh_config ), if you’re root and and to make changes for all the users, or your own config file ( $HOME/.ssh/config ).
Follow the example, and remember to customize to your needs
Now you can ssh into that server using:
If you wish you could use friendly names to access your servers, here’s how to do it:
Edit your ~/.ssh/config and add the following:
Please, remember to customize "HostName" and "User" values to your needs. 🙂
Create a file ~/.ssh/config and insert the following:
mauricio@rynex:~$ cat .ssh/config
Change according to your servername, username and port, of course.
Then you can simply use:
to connect to the server instead of using:
Make your server trust your laptop+user:
#su - "your username here"
$ssh-keygen -t rsa
$scp ~/.ssh/id_rsa.pub "remote_username"@"host_name":"target_filepath_for_key_on_the_server"
Now ssh into your server:
Insert your laptop’s public key in the authorized keys list:
$cat "target_filepath_for_key_on_the_server" >> authorized_keys
Try ssh-ing your server again (this time you should not need to type a password:
Create an alias for your server:
and add this (customize it, please):
Now you should be able to ssh into your server like this:
Now use this nice backup script:
TODAY_FOLDER=/home/backup/`date +%Y-%m-%d --date "0 day ago"`/linode
YESTERDAY_FOLDER=/home/backup/`date +%Y-%m-%d --date "1 day ago"`/linode
if [ -e $pid ]
echo "Still running..."
if [ ! -d $TODAY_FOLDER ]; then
mkdir -p $TODAY_FOLDER
cp -alv $YESTERDAY_FOLDER/. $TODAY_FOLDER
rsync --bwlimit=100 --force --no-p --progress --delete-before -aze ssh linode:~/ $TODAY_FOLDER
and you will have full backups (while preserving spaces as the cp command creates hardlinks) daily
To avoid copying and pasting my password (mostly in the wrong window), I thought it would be better to make my server trust my laptop by using public/private keys:
Here we go:
For Linux (or BSD, or OSX):
1. Open a terminal on your laptop and generate your keys:
ssh-keygen -t rsa
You may optionally choose a passphrase (which I didn’t since the I want to avoid typing).
2. Copy the public key to your server:
scp ~/.ssh/id_rsa.pub username@server_address:/your/home/folder/
3. SSH into your server and add your public key to the authorized_keys file:
echo "#Something to identify your key" >> authorized_keys
cat /your/home/folder/id_rsa.pub >> authorized_keys
4. Open another terminal and try logging to your server just providing your username:
You should be granted with the shell command line from your server. If not, please review what you did. If still doesn’t work, drop me a line: