module-mysql/files/backup_helpers/mysql_extract_from_backup.sh

18 lines
394 B
Bash
Raw Normal View History

2013-02-18 22:13:56 +01:00
#!/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