Last active
November 1, 2015 17:15
-
-
Save paulohrpinheiro/bae14959fe7bc0d34dee to your computer and use it in GitHub Desktop.
MySQL Parallel Restore
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
#!/usr/bin/env bash | |
DB="DATABASE_NAME" | |
DB_AUTH="-uroot -ptoor" | |
DB_BACKUP_DIR="/some/location" | |
DB_GLOB_FOR_BACKUP="dump-*.gz" | |
MAX_JOBS=30 | |
cd $DB_BACKUP_DIR || exit | |
for table_dump_file in `ls -S1 $DB_GLOB_FOR_BACKUP` | |
do | |
echo $table_dump_file | |
{ | |
echo "SET unique_checks=0; SET autocommit=0; SET foreign_key_checks=0;"; | |
zcat $table_dump_file; | |
echo " SET unique_checks=1; SET autocommit=1; SET foreign_key_checks=1; COMMIT;"; | |
} | mysql --force $DB_AUTH $DB & | |
present_jobs=$(jobs|wc -l) | |
if [ $present_jobs -ge $JOBS ] | |
then | |
wait -n | |
fi | |
done | |
echo "Really last background processes:" | |
jobs | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment