Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Last active November 1, 2015 17:15
Show Gist options
  • Save paulohrpinheiro/bae14959fe7bc0d34dee to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/bae14959fe7bc0d34dee to your computer and use it in GitHub Desktop.
MySQL Parallel Restore
#!/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