Skip to content

Instantly share code, notes, and snippets.

@udienz
Created January 12, 2015 06:20
Show Gist options
  • Select an option

  • Save udienz/bf86cf701de5ac53a3de to your computer and use it in GitHub Desktop.

Select an option

Save udienz/bf86cf701de5ac53a3de to your computer and use it in GitHub Desktop.
mysql backup entire database
#!/bin/bash
# 2014, Mahyuddin Susanto <[email protected]>
set -x
SQLPASS=WHATEVER
ARGS="-u root -h 202.154.57.61 -p$SQLPASS"
SAVE="$HOME/mysql-backup/$(hostname -f)/$(date +%Y%m%d%H%M)"
# remove database backup older that 90 days
find $HOME/mysql-backup -mtime +90 | xargs rm -rf
if ! [ -d $SAVE ]; then
mkdir $SAVE -p
fi
cd $SAVE
do_process () {
mysqldump $ARGS $1 | gzip -9c > $SAVE/$1.sql.gz
}
echo 'show databases;' | mysql $ARGS | sed -e '/Database/d' -e '/information_schema/d' -e '/performance_schema/d' -e '/mysql/d' | while read data
do
do_process $data
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment