Remote Backup of Files, Subversion, and MySQL Using Rsync and Ssh

June 13, 2010

TuxRecently my VPS provider was doing some power maintenance and recommended backing up data.  I realized I hadn't made a backup of that system in very long time, and hadn't worked up a backup strategy.  This caused me to whip up a backup solution using my two favorite things; ssh and rsync.

In the past I had used tar and scp to do remote backups, but this painfully slow, and I don't have a requirement to do moment in time backups, so the amazing efficiency of rsync.  The only trick was that this server has subversion and MySQL databases, and doing a straight copy of the data for these apps is extremely dangerous.  So with a couple remote ssh commands run from the backup machine I ended up with a slick, simple, fast, and reliable backup script:

#!/bin/bash

# Individually backup relevant etc configurations using rsync
# with the archive and compressions flags set
rsync -az -e "ssh -i path/to/ssh/key" backup_user@example.org:/etc/apache2 /data/backup/etc/
.
.
rsync -az -e "ssh -i path/to/ssh/key" backup_user@example.org:/etc/ssl /data/backup/etc/

# Use remote commands to trigger app specific backups for MySQL and subversion

# Run safe backup of all MySQL databases to a location that gets rsynced later
ssh -i path/to/ssh/key backup_user@example.org "mysqldump -u root -pPassword --all-databases > /opt/backup/mysql-current.sql"

# Run safe backup of subversion using svnadmin dump to a directory that gets rsynced
ssh -i path/to/ssh/key backup_user@example.org "svnadmin dump --quiet /opt/repos/svn > /opt/backup/svn.current.dump"

# Sync /opt.  Backup everything.  This will grab the remote MySQL and subversion backups
# we just made.
rsync -az -e "ssh -i path/to/ssh/key" backup_user@cexample.org:/opt/ /data/backup/opt/

That is it. I get a safe backup of my databases and svn plus all of my file data ~8 GiB total, and after the initial backup it all happens in less than 5 minutes.

Attach it all to crontab like:

0 * * * * /usr/local/bin/backup.py

and you get an hourly synchronized copy of the remote server.

 

 

tags: FOSS, IT, System, VPS

Comments

1 driegealieme says...
http://legalusdrugstore.com/22.jpg pharmacy technician requirements for texas http://legalexclusivepharmacy.com/catalog/Pain_Relief/Maxalt.htm cvs pharmacy camp bowie fort worth Inderal online pharmacy ativan jennifer chan pharmacy faculty
February 14, 2012 at 3:05 a.m.
2 wouttyTok says...
Join the FacesEpicentre.com community to meet new people from around the world! http://facesepicentre.com/facesepicentre2.jpg xxx social network http://facesepicentre.com/ social networks video list belgi and social network social networks reviewed by employers acc adoption social network leadership social networks malaysian chinese social network social network scott phillips michigan ohio
February 17, 2012 at 3:04 a.m.
3 inhippinailI says...
http://legalusdrugstore.com/21.jpg cheap butalbital online from usa pharmacy http://chepestmedications.net/products/horny-goat-weed.htm dba parkside pharmacy santa monica ca prevacid ga board of pharmacy technicians http://chepestmedications.net/products/nimotop.htm blank job application for a pharmacy technition pharmacy technician schools online us discount pharmacy ambien no prescription http://chepestmedications.net/products/hydrochlorothiazide.htm health pharmacy drugs medications zolpidem indinavir online pharmacy cipro http://chepestmedications.net/products/xenical.htm online pharmacy prozac techskills pharmacy tech program
March 19, 2012 at 8:58 p.m.
4 LoobWimbita says...
hipaa and pharmacy http://www.fda-approved-pharmacy.com/products/ranitidine.htm online pharmacy consultation
March 28, 2012 at 7:50 p.m.
5 Clieddiscemi says...
pelam pharmacy in massachusetts http://www.fda-approved-pharmacy.com/categories/skin-care.htm diazepam pharmacy
April 13, 2012 at 6:01 a.m.

Add your comment.