Last active
September 4, 2015 01:05
-
-
Save funkaoshi/239572 to your computer and use it in GitHub Desktop.
funkaoshi.com backup script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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