Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Last active February 22, 2025 11:08
Show Gist options
  • Save tdegrunt/be7118242a1c0b5045d254170cb92a96 to your computer and use it in GitHub Desktop.
Save tdegrunt/be7118242a1c0b5045d254170cb92a96 to your computer and use it in GitHub Desktop.
Bash script to restore specific tables
#!/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
@tdegrunt
Copy link
Author

Originally from https://dba.stackexchange.com/a/223195, amended a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment