Skip to content

Instantly share code, notes, and snippets.

@mklooss
Created January 20, 2014 13:52
Show Gist options
  • Select an option

  • Save mklooss/8520191 to your computer and use it in GitHub Desktop.

Select an option

Save mklooss/8520191 to your computer and use it in GitHub Desktop.
Magento MySQL Dump
#!/bin/bash
MYSQL_HOST=`xmllint --nocdata --xpath 'string(//config/global/resources/default_setup/connection/host)' app/etc/local.xml`
MYSQL_PASS=`xmllint --nocdata --xpath 'string(//config/global/resources/default_setup/connection/password)' app/etc/local.xml`
MYSQL_USER=`xmllint --nocdata --xpath 'string(//config/global/resources/default_setup/connection/username)' app/etc/local.xml`
MYSQL_DB=`xmllint --nocdata --xpath 'string(//config/global/resources/default_setup/connection/dbname)' app/etc/local.xml`
BACKUPDIR="$HOME/backups/sql"
DIRNAME=`date +%Y-%m-%d`;
GZIP=$(which gzip);
NICE=$(which nice);
MYSQLDUMP=$(which mysqldump);
FILENAME="$MYSQL_DB-`date +%Y_%m_%d_%H_%M_%S`.sql.gz";
FIND=$(which find);
mkdir -p "$BACKUPDIR/$DIRNAME"
$NICE -n 20 $MYSQLDUMP -e --default-character-set=utf8 -u $MYSQL_USER -p"$MYSQL_PASS" -h $MYSQL_HOST $MYSQL_DB | $NICE -n 20 $GZIP -c > "$BACKUPDIR/$DIRNAME/$FILENAME";
$FIND $BACKUPDIR -depth -mtime +7 -exec rm -rf '{}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment