]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/updatedb/update_mysql_tables_7_to_8
Tweak delta-test to use ofname instead of fixed name
[bacula/bacula] / bacula / updatedb / update_mysql_tables_7_to_8
index 8e41e871f5ba648d2b3c33680f7d7cb76b3266ff..8cd6ed1af56a55fea58a6fc6a6febf7c0198b02e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # Shell script to update MySQL tables from version 1.34 to 1.35.5
 #
 #
 # Shell script to update MySQL tables from version 1.34 to 1.35.5
 #
@@ -7,9 +7,27 @@ echo "This script will update a Bacula MySQL database from version 7 to 8"
 echo "Depending on the size of your database,"
 echo "this script may take several minutes to run."
 echo " "
 echo "Depending on the size of your database,"
 echo "this script may take several minutes to run."
 echo " "
-bindir=/home/kern/bacula/depkgs/sqlite
+bindir=/usr/bin
 
 
-if $bindir/mysql $* -f <<END-OF-DATA
+DB_VER=`$bindir/mysql $* bacula -e 'select * from Version;'|tail -n 1 2>/dev/null`
+if [ -z "$DB_VER" ]; then
+       echo "Sorry, I can't seem to locate a bacula database."
+       exit 1
+fi
+
+if [ -n "$DB_VER" ]; then
+
+       if [ "$DB_VER" = "8" ]; then
+               echo "The Catalog is already at version 8. Nothing to do!"
+               exit 0
+       elif [ "$DB_VER" -ne "7" ]; then
+               echo "Sorry, this script is designed to update a version 7 database"
+               echo "and you have a version $DB_VER database."
+               exit 1
+       fi
+fi
+
+if $bindir/mysql $* -f << END_OF_DATA
 USE bacula;
 
 ALTER TABLE Media ADD COLUMN EndFile INTEGER UNSIGNED NOT NULL DEFAULT 0;
 USE bacula;
 
 ALTER TABLE Media ADD COLUMN EndFile INTEGER UNSIGNED NOT NULL DEFAULT 0;
@@ -22,10 +40,11 @@ UPDATE Filename SET Name='' WHERE Name=' ';
 DELETE FROM Version;
 INSERT INTO Version (VersionId) VALUES (8);
 
 DELETE FROM Version;
 INSERT INTO Version (VersionId) VALUES (8);
 
-END-OF-DATA
+END_OF_DATA
 then
    echo "Update of Bacula MySQL tables succeeded."
 else
    echo "Update of Bacula MySQL tables failed."
 fi
 then
    echo "Update of Bacula MySQL tables succeeded."
 else
    echo "Update of Bacula MySQL tables failed."
 fi
+
 exit 0
 exit 0