summaryrefslogtreecommitdiff
path: root/files/backup_helpers/mysql_extract_from_backup.sh
blob: 74914e9e9bfeea2333795ae87e2e640bbac086d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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