summaryrefslogtreecommitdiff
path: root/files/backup_helpers/mysql_extract_from_backup.sh
diff options
context:
space:
mode:
Diffstat (limited to 'files/backup_helpers/mysql_extract_from_backup.sh')
-rw-r--r--files/backup_helpers/mysql_extract_from_backup.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/files/backup_helpers/mysql_extract_from_backup.sh b/files/backup_helpers/mysql_extract_from_backup.sh
new file mode 100644
index 0000000..74914e9
--- /dev/null
+++ b/files/backup_helpers/mysql_extract_from_backup.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+file=$1
+db=$2
+table=$3
+
+if [ ! -f $file ] || [ -z $db ]; then
+ echo "USAGE: $0 file database [table] > dump_file"
+ exit
+fi
+
+if [ -z $table ]; then
+ zcat $file | sed -n -e "/CREATE DATABASE.*${db}/,/CREATE DATABASE/p" | head -n -5
+else
+ zcat $file | sed -n -e "/CREATE DATABASE.*${db}/,/CREATE DATABASE/p" | sed -n -e "/CREATE TABLE.*${table}/,/CREATE TABLE/p" | head -n -8
+fi
+