Last active
February 22, 2025 11:08
-
-
Save tdegrunt/be7118242a1c0b5045d254170cb92a96 to your computer and use it in GitHub Desktop.
Bash script to restore specific tables
This file contains 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 | |
dump_file='db.dump' | |
# Where to restore | |
db_host='' | |
db_name='dbname' | |
db_user='' | |
db_pass='' | |
tbl_list=("waybillHistory" "waybillOrderLine" "webhook" "xmlLogin" "zipcode") | |
for tbl in "${tbl_list[@]}" | |
do | |
echo "Extracting $tbl" | |
# # extract the content between drop table and Table structure for, also replace the table name | |
echo "SET autocommit=0;" > tbl.sql | |
sed -n -e '/DROP TABLE IF EXISTS `'$tbl'`/,/\/*!40000 ALTER TABLE `'$tbl'` ENABLE KEYS \*\/;/p' $dump_file >> tbl.sql | |
echo "COMMIT;" >> tbl.sql | |
echo "Importing $tbl" | |
mysql -h $db_host -u $db_user -p"$db_pass" $db_name -A < tbl.sql | |
rm -f tbl.sql | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally from https://dba.stackexchange.com/a/223195, amended a bit