| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Shell script to update PostgreSQL tables from version 1.34 to 1.35.5 |
| 4 |
# |
| 5 |
echo " " |
| 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." |
| 9 |
echo " " |
| 10 |
bindir=/usr/bin |
| 11 |
|
| 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." |
| 15 |
exit 1 |
| 16 |
fi |
| 17 |
|
| 18 |
if [ -n "$DB_VER" ]; then |
| 19 |
|
| 20 |
if [ "$DB_VER" = "8" ]; then |
| 21 |
echo "The Catalog is already at version 8. Nothing to do!" |
| 22 |
exit 0 |
| 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." |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
fi |
| 29 |
|
| 30 |
|
| 31 |
if $bindir/psql $* -f - <<END_OF_DATA |
| 32 |
\c bacula |
| 33 |
|
| 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; |
| 40 |
|
| 41 |
UPDATE Filename SET Name='' WHERE Name=' '; |
| 42 |
|
| 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; |
| 48 |
|
| 49 |
DELETE FROM Version; |
| 50 |
INSERT INTO Version (VersionId) VALUES (8); |
| 51 |
|
| 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); |
| 56 |
|
| 57 |
create table CDImages |
| 58 |
( |
| 59 |
MediaId integer not null, |
| 60 |
LastBurn timestamp without time zone not null, |
| 61 |
primary key (MediaId) |
| 62 |
); |
| 63 |
|
| 64 |
vacuum; |
| 65 |
|
| 66 |
END_OF_DATA |
| 67 |
then |
| 68 |
echo "Update of Bacula PostgreSQL tables succeeded." |
| 69 |
else |
| 70 |
echo "Update of Bacula PostgreSQL tables failed." |
| 71 |
fi |
| 72 |
exit 0 |