Skip to content

Instantly share code, notes, and snippets.

@funkaoshi
Last active September 4, 2015 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkaoshi/239572 to your computer and use it in GitHub Desktop.
Save funkaoshi/239572 to your computer and use it in GitHub Desktop.
funkaoshi.com backup script.
#!/bin/sh
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/Users/ramanan/local/bin:$PATH"
# dump database, downlaod it locally, restore it over local copy
# of the database. Everything is done in /tmp/
cd /tmp/
# cd to the tmp directory on funkaoshi.com; dump the database
# out of mysql, and gzip it up.
ssh ramanan@funkaoshi.com 'cd /home/ramanan/local/tmp; mysqldump funkaoshi | gzip -f > funkaoshi.sql.gz'
# copy the zip'd database dump to my computer; unzip it on my box
scp ramanan@funkaoshi.com:/home/ramanan/local/tmp/funkaoshi.sql.gz .
gunzip funkaoshi.sql.gz
# start up mysql, since I normally use postgres.
mysql.server start
# overwrite my dev database with the data from live server
mysql -D funkaoshi < funkaoshi.sql
# archive the data using git, so we keep versioned snapshots
mv funkaoshi.sql /Users/ramanan/local/backups/funkaoshi.db/funkaoshi.sql
cd /Users/ramanan/local/backups/funkaoshi.db/
git add .
git commit -m 'Import data from webserver.'
# archive files from funkaoshi.com locally
cd /Users/ramanan/local/backups/
rsync -azve ssh ramanan@funkaoshi.com:/home/ramanan/funkaoshi.com .
# update site prefs so we can view local copy of site from localhost/funkaoshi.com
mysql -D funkaoshi -e "update txp_prefs set val='localhost/funkaoshi.com' where name='siteurl'"
# shut down mysql
mysql.server stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment