diff options
author | mh <mh@immerda.ch> | 2013-02-18 22:13:56 +0100 |
---|---|---|
committer | Marcel Haerry <haerry@puzzle.ch> | 2013-02-19 10:12:35 +0100 |
commit | 6d9a84686734e598249410bf60eedf2d7fd2e521 (patch) | |
tree | fbd7fcb746620a61f8adda2ea3d2f3e9473a6cf5 /files/backup_helpers | |
parent | fc1210bea8931648e7600c5d55d252fed4b17cc2 (diff) |
introduce helpers for mysql backups
Diffstat (limited to 'files/backup_helpers')
-rw-r--r-- | files/backup_helpers/mysql_extract_from_backup.sh | 17 |
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 + |