Skip to content

Instantly share code, notes, and snippets.

@leeky
Created August 23, 2010 15:34
Show Gist options
  • Save leeky/545722 to your computer and use it in GitHub Desktop.
Save leeky/545722 to your computer and use it in GitHub Desktop.
1) Make sure .ssh directory exists on remote server
2) Generate SSH key using ssh-keygen -t rsa
3) Copy public key onto remote server and append to ~/.ssh/authorised_keys2
4) Test password-less SSH onto remote server, might need to edit ~/.ssh/config
Host shortname
HostName ipaddr
Port blah (if port not 22)
User blah (if user not the same as local user)
5) rsync -e "ssh -p port" -rca --delete-after shortname:/path/to/files/ /local/backup/path/
6) copy this line into backup.sh file in home directory
#!/bin/sh
rsync ... (as above)
7) Edit crontab with "crontab -e" and insert the following:
15 11 * * * yourusername ~yourusername/backup.sh
In this example, you'll schedule a daily backup at 11.15am each day
Optional: create backup archives
--------------------------------
tar cfx /local/archive/path/server_name_`date +%Y-%m-%d`.tar.gz /local/backup/path/*
MySQL Backups
=============
1) ssh shortname "mysqldump -u mysqluser --password=mysqlpass database_name | gzip -9 > database_name.sql.gz"
2) scp shortname:/path/to/mysql.sql.gz /local/backup/path/mysql.sql.`date +%Y-%m-%d`.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment