Splitter un dump mysql avec Bash, en 1 dump par table

#!/bin/bash

file=$1 # the input file
directory= »$file-splitted » # the output directory
output= »$directory/header » # the first file containing the header
GREP= »DROP TABLE » # what we are looking for

mkdir $directory # create the output directory

while read line
do
# if the current line contains the wanted statement
if [ $(echo « $line » | grep -c « $GREP ») == « 1 » ]
then
# extract the file name
myfile=$(echo $line | awk ‘{print $5}’ | sed -e ‘s/`//g’ -e ‘s/;//g’)
# set the new file name
output= »$directory/$myfile »
fi
echo « $line » >> $output # write to file
done < $file

Retour en haut