<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Package: <span style="font-family:monospace;">
<span style="background-color:#ffffff;"><span style="color:#000000;">bacula-director-pgsql</p>
<p> </span></span></span>Version: <span style="background-color:#ffffff;"><span style="color:#000000;">15.0.3-3</span></span><br>
</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">When I invoke
</p>
<p> <span style="background-color:#ffffff;"><span style="color:#000000;">sudo -u postgres /usr/share/bacula-director/</span></span><span style="background-color:#000000;"><span style="color:#ffffff;">update_postgresql_tables</span></span><span style="background-color:#ffffff;"><span style="color:#000000;"> -d
 <bacula_database><br>
The Baculadatabase isnt' upgraded due to a few "errors" in the script.</span></span></p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">The First error the psql dump is created without a -q, this causes that header data ends up in the file. Because of this the restore fails.</p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Secondly the postgresql do $$ is not correctly escaped. Therefore bash replaces the $$ to the current process id.</p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><br>
</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">  I suggest the following patch:</p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> <span style="background-color:#ffffff;"><span style="color:#000000;">--- /usr/share/bacula-director/update_postgresql_tables.orig    2025-04-24 15:00:09.000000000 +0000
</span></span><br>
+++ /usr/share/bacula-director/update_postgresql_tables 2025-09-02 11:44:35.755581836 +0000
<br>
@@ -186,7 +186,7 @@ <br>
    echo " doesn't have write permission on the current directory," <br>
    echo " or if the system doesn't have enough space to store a" <br>
    echo " compressed export of the File table" <br>
-    psql --set ON_ERROR_STOP=1 -d ${db_name} $* -c "set work_mem='$WORKMEM';"'set enable_mergejoin to off ; set enable_hashjoin to off; copy (SELECT FileId, FileIndex, JobId, PathId, Filename.Name, DeltaSeq, Ma<br>
rkId, LStat, Md5 FROM File JOIN Filename USING (FilenameId)) TO STDOUT' | $COMP -1 -c > file1017.data
<br>
+    psql -q --set ON_ERROR_STOP=1 -d ${db_name} $* -c "set work_mem='$WORKMEM';"'set enable_mergejoin to off ; set enable_hashjoin to off; copy (SELECT FileId, FileIndex, JobId, PathId, Filename.Name, DeltaSeq,<br>
MarkId, LStat, Md5 FROM File JOIN Filename USING (FilenameId)) TO STDOUT' | $COMP -1 -c > file1017.data
<br>
     <br>
    if [ $? -ne 0 ]; then <br>
       echo "Error while dumping file table to $PWD/file1017.data" <br>
@@ -285,7 +285,7 @@ <br>
    echo " doesn't have write permission on the current directory," <br>
    echo " or if the system doesn't have enough space to store a" <br>
    echo " compressed export of the File table" <br>
-    psql --set ON_ERROR_STOP=1 -d ${db_name} $* -c "set work_mem='$WORKMEM';"'set enable_mergejoin to off ; set enable_hashjoin to off; copy (SELECT FileId, FileIndex, JobId, PathId, Filename.Name, DeltaSeq, Ma<br>
rkId, LStat, Md5 FROM File JOIN Filename USING (FilenameId)) TO STDOUT' | $COMP -1 -c > file1016.data
<br>
+    psql -q --set ON_ERROR_STOP=1 -d ${db_name} $* -c "set work_mem='$WORKMEM';"'set enable_mergejoin to off ; set enable_hashjoin to off; copy (SELECT FileId, FileIndex, JobId, PathId, Filename.Name, DeltaSeq,<br>
MarkId, LStat, Md5 FROM File JOIN Filename USING (FilenameId)) TO STDOUT' | $COMP -1 -c > file1016.data
<br>
     <br>
    if [ $? -ne 0 ]; then <br>
       echo "Error while dumping file table to $PWD/file1016.data" <br>
@@ -642,7 +642,7 @@ <br>
 <br>
-- Need to add postgresql-contrib to the dependency list <br>
 <br>
-do $$ <br>
+do \$\$ <br>
declare <br>
  selected_ext pg_extension%rowtype; <br>
begin   <br>
@@ -654,7 +654,7 @@ <br>
  if not found then <br>
     CREATE EXTENSION pg_trgm; <br>
  end if; <br>
-end $$; <br>
+end \$\$; <br>
 <br>
CREATE INDEX meta_emailowner on MetaEmail (EmailTenant, EmailOwner); <br>
CREATE INDEX meta_emailtime on MetaEmail (EmailTime);<br>
</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Regards,</p>
<p style="margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Joop Boonen.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><br>
</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">--</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Joop Boonen</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Professional services consultant</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">credativ IT Services GmbH</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Unser Umgang mit personenbezogenen Daten unterliegt folgenden Bestimmungen: https://www.credativ.de/datenschutz</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><br>
</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">credativ IT Services GmbH, Trompeterallee 108, 41189 Mönchengladbach, Germany</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Handelsregister: AG Mönchengladbach HRB 23003</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Geschäftsführer: David Brauner</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Umsatzsteuer-ID: DE452151696
</p>
</body>
</html>