]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/database/bacula-sqlite_2_mysqldump.sh
Implement RestoreObject for sqlite + cleanups
[bacula/bacula] / bacula / examples / database / bacula-sqlite_2_mysqldump.sh
1 #! /bin/sh
2 #
3 # bacula-sqlite_2_mysqldump.sh
4 #
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
8 #
9
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."
14         echo
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"
17         exit
18 fi
19
20 # If $1 is '-' then cat will read /dev/stdin
21 cat $1 |
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'