From 6d9a84686734e598249410bf60eedf2d7fd2e521 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 18 Feb 2013 22:13:56 +0100 Subject: introduce helpers for mysql backups --- files/backup_helpers/mysql_extract_from_backup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 files/backup_helpers/mysql_extract_from_backup.sh (limited to 'files') 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 + -- cgit v1.2.3