3 # Shell script to update PostgreSQL tables from version 1.34 to 1.35.5
6 echo "This script will update a Bacula PostgreSQL database from version 7 to 8"
7 echo "Depending on the size of your database,"
8 echo "this script may take several minutes to run."
12 DB_VER="`echo -e '\\c bacula\nselect * from Version;' | $bindir/psql $* bacula -f - | tail -n 1 2>/dev/null`"
13 if [ -z "$DB_VER" ]; then
14 echo "Sorry, I can't seem to locate a bacula database."
18 if [ -n "$DB_VER" ]; then
20 if [ "$DB_VER" = "8" ]; then
21 echo "The Catalog is already at version 8. Nothing to do!"
23 elif [ "$DB_VER" -ne "7" ]; then
24 echo "Sorry, this script is designed to update a version 7 database"
25 echo "and you have a version $DB_VER database."
31 if $bindir/psql $* -f - <<END_OF_DATA
34 ALTER TABLE media ADD COLUMN EndFile integer;
35 UPDATE media SET EndFile=0;
36 ALTER TABLE media ALTER COLUMN EndFile SET NOT NULL;
37 ALTER TABLE media ADD COLUMN EndBlock bigint;
38 UPDATE media SET EndBlock=0;
39 ALTER TABLE media ALTER COLUMN EndBlock SET NOT NULL;
41 UPDATE Filename SET Name='' WHERE Name=' ';
43 alter table file alter column filenameid rename to filenameid-old;
44 alter table file add column filenameid integer;
45 update file set filenameid = filenameid-old;
46 alter table file alter column filenameid set not null;
47 alter table file drop column filenameid-old;
50 INSERT INTO Version (VersionId) VALUES (8);
52 create index file_jobid_idx on file (jobid);
53 create index file_pathid_idx on file(pathid);
54 create index file_filenameid_idx on file(filenameid);
55 create index file_jpfid_idx on file (jobid, pathid, filenameid);
59 MediaId integer not null,
60 LastBurn timestamp without time zone not null,
68 echo "Update of Bacula PostgreSQL tables succeeded."
70 echo "Update of Bacula PostgreSQL tables failed."