Created
December 12, 2012 14:51
-
-
Save devopsmariocom/4268338 to your computer and use it in GitHub Desktop.
Simple guide to re-dump mysql database
This file contains hidden or 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/bash | |
tmp_dir=/tmp/database_redump | |
timestamp=$(date +\%Y_\%m_\%d_\%H%M) | |
tmp_dump_file="${tmp_dir}/${timestamp}.sql" | |
mkdir -p $tmp_dir | |
echo "Dumping all databases to file $tmp_dump_file" | |
mysqldump --all-databases > $tmp_dump_file | |
echo "" | |
echo "Verify your dump and drop all databases" | |
echo "less $tmp_dump_file" | |
echo "" | |
echo "Drop all your databases" | |
mysql -B -e "show databases;" | egrep -v "Database|information_schema" | xargs -0 echo mysqladmin drop | |
echo "" | |
echo "Stop Database" | |
echo "/etc/init.d/mysqld stop" | |
echo "" | |
echo "Remove ibdata1" | |
echo "rm /var/lib/mysql/ibdata1" | |
echo "" | |
echo "Start Database" | |
echo "/etc/init.d/mysqld start" | |
echo "" | |
echo "Redump database back" | |
echo "mysql < $tmp_dump_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment