Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Last active August 29, 2015 14: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 waynegraham/5493609839a596f279c4 to your computer and use it in GitHub Desktop.
Save waynegraham/5493609839a596f279c4 to your computer and use it in GitHub Desktop.
Dump mysql based on omeka db.ini file

Save the file on the server as ~/bin/dump and change the executable bit on it.

$ chmod +x ~/bin/dump

Then make sure ~/bin in your $PATH

$ export PATH=~/bin/:$PATH

Now, in an omeka project, run dump.

#! /usr/bin/env bash
path="."
CURDATE=$( date +%Y-%m-%d-%s )
DBUSER=$( cat ${path}/db.ini | grep "^username" | awk -F\" '{print $(NF-1)}' )
DBPASS=$( cat ${path}/db.ini | grep "^password" | awk -F\" '{print $(NF-1)}' )
DBNAME=$( cat ${path}/db.ini | grep "^dbname" | awk -F\" '{print $(NF-1)}' )
DBPREF=$( cat ${path}/db.ini | grep "^prefix" | awk -F\" '{print $(NF-1)}' )
DBHOST=$( cat ${path}/db.ini | grep "^host" | awk -F\" '{print $(NF-1)}' )
DBPORT=$( cat ${path}/db.ini | grep "^port" | awk -F\" '{print $(NF-1)}' )
echo "Dumping database"
mysqldump -h $DBHOST -u $DBUSER --password="$DBPASS" $DBNAME | gzip -c | cat > $DBNAME-$CURDATE.sql.gz
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment