3 # bacula-sqlite_2_mysqldump.sh
5 # Convert a Bacula 1.36.2 Sqlite database to MySQL
6 # Originally Written by Nic Bellamy <nic@bellamy.co.nz>, Sept/Oct 2003.
7 # Modified by Silas Bennett <silas.bennett_AT_ge.com>, April 2006 for use with Bacula 1.36.2
10 if [ $1 = '-h' ] || [ $1 = '--help' ] ; then
11 echo `basename "$0"`" Usage:"
12 echo " "`basename $0`" takes a ASCII bacula sqlite database dump as an argument,"
13 echo " and writes an SQL dump suitable for use with MySQL to STDOUT."
15 echo " Example Use: "`basename $0`" bacula.sqlite.sql > bacula.mysql.sql"
16 echo " Example Use: "cat bacula.sqlite.sql | `basename $0`" - | mysql -p -u <user> baculadb"
20 # If $1 is '-' then cat will read /dev/stdin
22 awk '/^INSERT INTO / && $3 != "NextId" && $3 != "Version" { print $0 }' |
23 sed '/^INSERT INTO [a-zA-Z]* VALUES(/s/(NULL)/(0)/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/(NULL,/(0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL,/,0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL,/,0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL)/,0)/g'