echo " "
echo "This script will update a Bacula SQLite database from version 12-15 to 16"
echo " "
-echo "Depending on the current version of your catalog, you may have to run this script"
-echo " multiple times"
+echo "Depending on the current version of your catalog,"
+echo "you may have to run this script multiple times"
echo " "
bindir=@SQLITE_BINDIR@
PATH="$bindir:$PATH"
cd @working_dir@
db_name=@db_name@
-
DBVERSION=`sqlite3 ${db_name}.db <<END
SELECT VersionId FROM Version LIMIT 1;
END
echo " "
echo "The existing database is version $DBVERSION !!"
echo "This script can only update an existing version 12, 13, 14 or 15 database to version 16."
- echo "Error. Cannot upgrade this database."
+ echo "Error. Cannot upgrade this database, which has version $DBVERSION.."
echo " "
exit 1
fi
CREATE INDEX jobtdate_idx on JobHisto (JobTDate);
UPDATE Version SET VersionId=15;
+COMMIT;
+
+END-OF-DATA
+
+DBVERSION=15
+fi
if [ "$DBVERSION" -eq 15 ] ; then
- if psql -f - -d ${db_name} $* <<END-OF-DATA
-begin;
+ sqlite3 $* ${db_name}.db <<END-OF-DATA
+
+BEGIN;
CREATE TABLE basefiles_temp (
BaseId BIGINT,
BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
SELECT BaseId, BaseJobId, JobId, FileId, FileIndex
FROM BaseFiles;
+CREATE TABLE new_Media (
+ MediaId INTEGER,
+ VolumeName VARCHAR(128) NOT NULL,
+ Slot INTEGER DEFAULT 0,
+ PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
+ MediaType VARCHAR(128) NOT NULL,
+ MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
+ LabelType TINYINT DEFAULT 0,
+ FirstWritten DATETIME DEFAULT 0,
+ LastWritten DATETIME DEFAULT 0,
+ LabelDate DATETIME DEFAULT 0,
+ VolJobs INTEGER UNSIGNED DEFAULT 0,
+ VolFiles INTEGER UNSIGNED DEFAULT 0,
+ VolBlocks INTEGER UNSIGNED DEFAULT 0,
+ LastPartBytes BIGINT UNSIGNED DEFAULT 0,
+ VolMounts INTEGER UNSIGNED DEFAULT 0,
+ VolBytes BIGINT UNSIGNED DEFAULT 0,
+ VolABytes BIGINT UNSIGNED DEFAULT 0,
+ VolAPadding BIGINT UNSIGNED DEFAULT 0,
+ VolHoleBytes BIGINT UNSIGNED DEFAULT 0,
+ VolHoles INTEGER UNSIGNED DEFAULT 0,
+ VolType INTEGER UNSIGNED DEFAULT 0,
+ VolParts INTERGER UNSIGNED DEFAULT 0,
+ VolCloudParts INTERGER UNSIGNED DEFAULT 0,
+ VolErrors INTEGER UNSIGNED DEFAULT 0,
+ VolWrites BIGINT UNSIGNED DEFAULT 0,
+ VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
+ VolStatus VARCHAR(20) NOT NULL,
+ Enabled TINYINT DEFAULT 1,
+ Recycle TINYINT DEFAULT 0,
+ ActionOnPurge TINYINT DEFAULT 0,
+ CacheRetention BIGINT UNSIGNED DEFAULT 0,
+ VolRetention BIGINT UNSIGNED DEFAULT 0,
+ VolUseDuration BIGINT UNSIGNED DEFAULT 0,
+ MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
+ MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
+ MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
+ InChanger TINYINT DEFAULT 0,
+ StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
+ DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
+ MediaAddressing TINYINT DEFAULT 0,
+ VolReadTime BIGINT UNSIGNED DEFAULT 0,
+ VolWriteTime BIGINT UNSIGNED DEFAULT 0,
+ EndFile INTEGER UNSIGNED DEFAULT 0,
+ EndBlock INTEGER UNSIGNED DEFAULT 0,
+ LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
+ RecycleCount INTEGER UNSIGNED DEFAULT 0,
+ InitialWrite DATETIME DEFAULT 0,
+ ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
+ RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
+ Comment TEXT,
+ PRIMARY KEY(MediaId)
+ );
+
+INSERT INTO new_Media (MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId, LabelType, FirstWritten, LastWritten, LabelDate, VolJobs, VolFiles, VolBlocks, VolMounts, VolBytes, VolType, VolErrors, VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle, ActionOnPurge, VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId, MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock, LocationId, RecycleCount, InitialWrite, ScratchPoolId, RecyclePoolId, Comment) SELECT MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId, LabelType, FirstWritten, LastWritten, LabelDate, VolJobs, VolFiles, VolBlocks, VolMounts, VolBytes, VolParts, VolErrors, VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle, ActionOnPurge, VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId, MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock, LocationId, RecycleCount, InitialWrite, ScratchPoolId, RecyclePoolId, Comment FROM Media;
+DROP TABLE Media;
+ALTER TABLE new_Media RENAME TO Media;
+CREATE INDEX inx8 ON Media (PoolId);
+
+CREATE UNIQUE INDEX Media_Volumename_Id ON Media (VolumeName);
+
+
DROP TABLE BaseFiles;
ALTER TABLE basefiles_temp RENAME TO BaseFiles;
-ALTER TABLE Media RENAME COLUMN VolParts TO VolType;
-ALTER TABLE Media ADD COLUMN VolParts INTEGER DEFAULT 0;
-ALTER TABLE Media ADD COLUMN LastPartBytes BIGINT DEFAULT 0;
-ALTER TABLE Media ADD COLUMN CacheRetention BIGINT DEFAULT 0;
-ALTER TABLE Pool ADD COLUMN CacheRetention BIGINT DEFAULT 0;
CREATE INDEX job_jobtdate_inx ON job (JobTDate);
UPDATE Version SET VersionId=16;
-commit;
-END-OF-DATA
- then
- echo "Update of Bacula SQLite3 tables 15 to 16 succeeded."
- getVersion
- else
- echo "Update of Bacula SQLite3 tables 15 to 16 failed."
- exit 1
- fi
-fi
-
COMMIT;
+
END-OF-DATA
+DBVERSION=16
+
+fi
+
echo ""
echo "WARNING: !!!! SQLite3 is no longer supported. !!!!"
echo "WARNING: !!!! Please switch to MySQL or PostgreSQL !!!!"
echo "WARNING: !!!! as soon as possible. !!!!"
echo ""
-
-
-DBVERSION=16
-fi