Skip to content

Instantly share code, notes, and snippets.

@yuxel
Last active August 29, 2015 13:57
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 yuxel/9400269 to your computer and use it in GitHub Desktop.
Save yuxel/9400269 to your computer and use it in GitHub Desktop.
#!/bin/bash
user="root"
pass="12345678"
excludeList="mysql|performance_schema|information_schema" #dont remove these databases
tmpDir="/tmp"
# PART1
# Uncomment first block to get your database dumps into tmpDir
# databases=`mysql -u ${user} -p${pass} -e 'show databases\G' | grep -i database | egrep -v "${excludeList}" | sed -e 's/^Database: '//`
#
# for i in $databases
# do
# echo "Creating backup files for $i"
# mysqldump -u ${user} -p${pass} $i > ${tmpDir}/backup_$i.sql
# echo "Dropping database: $i"
# mysql -u ${user} -p${pass} -e "drop database \`$i\`"
# done
#
# echo "Now Stop MySql (make sure process terminated) delete ibdata1 and ib_log files and then restart mysql"
# PART2
# After removing ibdata1 file comment block on PART1 and uncomment these to restore your database
# for i in `ls ${tmpDir}/*.sql`
# do
# dbname=`basename $i | sed -e 's/backup_//' | sed -e 's/\.sql//'`
# echo "Importing data to $dbname"
# mysql -u ${user} -p${pass} -e "create database \`$dbname\`"
# mysql -u ${user} -p${pass} $dbname < $i
# done
#
# echo "Import finished, you can remove your backup files under ${tmpDir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment