Check in. Untested.

This commit is contained in:
Klaus-Uwe Mitterer 2016-03-27 21:19:38 +02:00
commit 6e248fcd81
3 changed files with 55 additions and 0 deletions

16
main.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
if [ -n "$1" ] exit 1
./splitDatabase.pl < $1
ls -m1|grep "_dump.sql" > databaseFiles.txt
while read line
do
databaseName=`echo $line|awk -F '_dump.sql' '{print $1}'`
echo $databaseName
mkdir $databaseName
sh splitTable.sh $line $databaseName
done < databaseFiles.txt
rm -f databaseFiles.txt

29
splitDatabase.pl Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/perl -w
use strict;
use warnings;
my $dbfile;
my $dbname = q{};
my $header = q{};
while (<>) {
if (m/-- Current Database\: \`([-\w]+)\`/) {
if (defined $dbfile && tell $dbfile != -1) {
close $dbfile or die "Could not close file!"
}
$dbname = $1;
open $dbfile, ">>", "$1_dump.sql" or die "Could not create file!";
print $dbfile $header;
print "Writing file $1_dump.sql ...\n";
}
if (defined $dbfile && tell $dbfile != -1) {
print $dbfile $_;
}
if (! $dbname) { $header .= $_; }
}
close $dbfile or die "Could not close file!"

10
splitTable.sh Normal file
View file

@ -0,0 +1,10 @@
DUMP_FILE=$1
TARGET_FOLDER=$2
for tablename in $(grep "Table structure for table " $1 | awk -F"\`" {'print $2'})
do
sed -n "/^- Table structure for table \`$tablename\`/,/^- Table structure for table/p" $1 > $TARGET_FOLDER/$tablename.sql
TABLE_COUNT=$((TABLE_COUNT+1))
done;
rm -f $1