]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/create_postgresql_database.in
Fix #1648 about make_catalog_backup.pl with multiple catalog
[bacula/bacula] / bacula / src / cats / create_postgresql_database.in
index 5ec7a8f7e945835dd333d2a374ad87431a315662..e5d8644b363fed931ed3a36665325567b3bb3a3d 100644 (file)
@@ -3,14 +3,59 @@
 # shell script to create Bacula database(s)
 #
 
-bindir=@SQL_BINDIR@
+PATH="@SQL_BINDIR@:$PATH"
+db_name=${db_name:-@db_name@}
 
-if $bindir/psql template1 $* -f - <<END-OF-DATA
-CREATE DATABASE bacula;
+#
+# use SQL_ASCII to be able to put any filename into
+#  the database even those created with unusual character sets
+
+PSQLVERSION=`psql -d template1 -c 'select version()' | awk '/PostgreSQL/ {print $2}' | cut -d '.' -f 1,2`
+
+#
+# Note, LC_COLLATE and LC_TYPE are needed on 8.4 and beyond, but are
+#   not implemented in 8.3 or below.
+# This must be updated for future versions of PostgreSQL
+#
+case ${PSQLVERSION} in
+   9.*)
+       ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
+   ;;
+   8.[456789])
+       ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
+    ;;
+    *)
+       ENCODING="ENCODING 'SQL_ASCII'"
+    ;;
+esac
+
+
+
+#
+# Please note: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#  We do not recommend that you use ENCODING 'SQL_UTF8'
+#  It can result in creating filenames in the database that
+#  cannot be seen or restored.
+# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+#
+#
+if psql -f - -d template1 $* <<END-OF-DATA
+\set ON_ERROR_STOP on
+CREATE DATABASE ${db_name} $ENCODING TEMPLATE template0;
+ALTER DATABASE ${db_name} SET datestyle TO 'ISO, YMD';
 END-OF-DATA
 then
-   echo "Creation of bacula database succeeded."
+   echo "Creation of ${db_name} database succeeded."
+else
+   echo " "
+   echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+   echo "!!!! Creation of ${db_name} database failed. !!!!"
+   echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+fi
+if psql -l ${dbname} | grep " ${db_name}.*SQL_ASCII" >/dev/null; then 
+   echo "Database encoding OK"
 else
-   echo "Creation of bacula database failed."
+   echo " "
+   echo "Database encoding bad. Do not use this database"
+   echo " "
 fi
-exit 0