Skip to content

Instantly share code, notes, and snippets.

@rgo
Created March 27, 2009 11:09
Show Gist options
  • Save rgo/86642 to your computer and use it in GitHub Desktop.
Save rgo/86642 to your computer and use it in GitHub Desktop.
Restore table mysql
#!/bin/bash
# Restore table(table+data or only data) from mysqldump file
#
# NOTE: 'foo' is the table to restore and 'bar' next table in backup.
# Restore one table
zcat backup_20090316-0200.sql.gz | awk '/Table structure for table .foo./,/Table structure for table .bar./{print}' > output.sql
# Restore only data from one table
zcat backup_20090316-0200.sql.gz | awk '/Dumping data for table .foo./,/Table structure for table .bar./{print}' > output.sql
# Find backup files in subdirectories and restore only data
find . -wholename './*/*gz' -print | xargs zcat | awk "/Dumping data for table .foo./,/Table structure for table .bar./{print}" >> foo_data.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment