]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/cats/update_sqlite3_tables.in
authorEric Bollengier <eric@baculasystems.com>
Mon, 11 May 2020 15:18:26 +0000 (17:18 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Apr 29 13:52:04 2020 +0200

    Update SQL scripts for Events table. Catalog format 1022

Author: Alain Spineux <alain@baculasystems.com>
Date:   Thu Oct 18 12:56:15 2018 +0200

    catalog: fix mixed catalog upgrade issues

    - Some upgrade procedures are not run when appropriate
    - Fix some version issues in comments and messages

Author: Kern Sibbald <kern@sibbald.com>
Date:   Sat Aug 11 21:20:22 2018 +0200

    Permit catalog to contain negative FileIndexes

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 27 16:06:06 2018 +0100

    Allow to copy/migrate jobs with plugins

    Up to now, the unique Job name is used by plugins as a key
    in some cases (for example as a snapshot name).
    The plugin can use this value to compute the backup set.
    For example, snapshot-diff previous current

    When using Copy/Migration, the unique Job name associated with a job
    is updated with a new name, leading to some confusion on the plugin
    side.

    With this patch, we associate the original Job name with the
    Copy/Migration job record in the catalog, and we can send this value
    to the Client. If we copy a job that was migrated, the original job
    is kept from one job record to an other.

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 13 14:13:54 2018 +0100

    Add Pool::MaxPoolBytes to the catalog. Catalog version is now 1020

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Jan 5 20:27:33 2017 +0100

    Add CacheRetention to the Media table

Author: Kern Sibbald <kern@sibbald.com>
Date:   Mon Jan 2 13:32:50 2017 +0100

    Fix bad definition of LastPartSize in update tables

Author: Kern Sibbald <kern@sibbald.com>
Date:   Tue Oct 11 09:48:34 2016 +0200

    Add new Cloud part info to catalog - update database version to 1019

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Apr 5 18:55:10 2016 +0200

    Implement FileMedia feature and FO_OFFSETS for plugin

     - Allow plugins to use the FO_OFFSETS option
     - Add SQL support in cats
     - Add bvfs commands
     - Add FileMedia handling in the Storage Daemon
     - Add use FO_OFFSETS option in test plugin
     - Add new sql scripts to configure.in
     - Update catalog version to 1018

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 24 16:46:46 2015 +0100

    Upgrade catalog version to 1017

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Sun Nov 3 17:32:19 2013 +0100

    Add missing FileTable column on JobHisto table

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Sep 20 16:49:17 2013 +0200

    Add FileTable attribute in Job table

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Sep 19 16:28:34 2013 +0200

    Add migration script for SQLite3

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri May 3 13:24:07 2013 +0200

    Cleanup update_xxxx_tables.in

    The script is now updating the schema step by step from version 12 to
    version 1015.

Author: Kern Sibbald <kern@sibbald.com>
Date:   Thu May 2 17:13:05 2013 +0200

    Add Holes to catalog

Author: Kern Sibbald <kern@sibbald.com>
Date:   Tue Feb 5 12:37:33 2013 +0100

    Add VolABytes to Media record + adapt Bacula code new DB version 1015

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Feb 28 17:04:26 2012 +0100

    Add Incomplete status in make_xxx_tables and update_xxx_tables

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Feb 23 11:39:53 2012 +0100

    Add update procedure from 5.2

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Feb 15 15:27:23 2012 +0100

    Update update_xxx_tables scripts for version 1014

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Jan 30 13:19:07 2012 +0100

    Update update_xxx_tables to convert 12,13 to 14

bacula/src/cats/update_sqlite3_tables.in

index 5b1f6e8a0c58fba658911d017a7e191a599ef5c1..0949c59d9d8377e9f95d56c71f337ed176f4a060 100644 (file)
@@ -1,33 +1,34 @@
 #!/bin/sh
 #
-# Copyright (C) 2000-2017 Kern Sibbald
+# Copyright (C) 2000-2020 Kern Sibbald
 # License: BSD 2-Clause; see file LICENSE-FOSS
 #
-# Shell script to update SQLite tables from Bacula Community version 
-#  5.0.x, 5.2.x, 7.0.x, 7.2.x, 7.4.x
+# Shell script to update SQLite3 tables from Bacula Enterprise version from 4.0.x to 12.4.x
 #
 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,"
-echo "you may have to run this script multiple times"
+echo "This script will update a Bacula SQLite3 database from version 12-14,1021 to 1022"
+echo " which is needed to convert from Bacula Enterprise version 4.0.x to 12.4.x"
+echo " or Bacula Community version 5.0.x, 5.2.x, 6.0.x to 10.0.x"
 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
 `
-if [ "$DBVERSION" -lt 12 -o "$DBVERSION" -gt 15 ] ; then
+if [ "$DBVERSION" -ne 1022 ] ; then
+  if [ "$DBVERSION" -lt 12 -o "$DBVERSION" -gt 14 ] ; then
     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, which has version $DBVERSION.."
+    echo "This script can only update an existing version 12, 13, 14 or 1014-1021 database to version 1022."
+    echo "Error. Cannot upgrade this database."
     echo " "
     exit 1
+  fi
 fi
 
 if [ "$DBVERSION" = 12 ] ; then
@@ -75,98 +76,92 @@ fi
 
 if [ "$DBVERSION" = 14 ] ; then
     sqlite3 $* ${db_name}.db  <<END-OF-DATA
-BEGIN;
-
 INSERT INTO Status (JobStatus,JobStatusLong,Severity) VALUES
    ('I', 'Incomplete Job',25);
+UPDATE Version SET VersionId=1014;
+END-OF-DATA
+DBVERSION=1014
+fi
+
+if [ "$DBVERSION" = 1014 ] ; then
+    sqlite3 $* ${db_name}.db  <<END-OF-DATA
+ALTER TABLE Media ADD COLUMN VolABytes BIGINT UNSIGNED DEFAULT 0;
+ALTER TABLE Media ADD COLUMN VolAPadding BIGINT UNSIGNED DEFAULT 0;
+ALTER TABLE Media ADD COLUMN VolHoleBytes BIGINT UNSIGNED DEFAULT 0;
+ALTER TABLE Media ADD COLUMN VolHoles INTEGER UNSIGNED DEFAULT 0;
+UPDATE Version SET VersionId=1015;
+END-OF-DATA
+DBVERSION=1015
+fi
+
+if [ "$DBVERSION" = 1015 ] ; then
+    sqlite3 $* ${db_name}.db  <<END-OF-DATA
 
-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,
-   VolMounts INTEGER UNSIGNED DEFAULT 0,
-   VolBytes BIGINT UNSIGNED DEFAULT 0,
-   VolParts INTEGER 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,
-   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,
-   VolABytes BIGINT UNSIGNED DEFAULT 0,
-   VolAPadding BIGINT UNSIGNED DEFAULT 0,
-   VolHoleBytes BIGINT UNSIGNED DEFAULT 0,
-   VolHoles INTEGER UNSIGNED DEFAULT 0,
-   PRIMARY KEY(MediaId)
+begin;
+CREATE TABLE file_temp (
+   FileId INTEGER,
+   FileIndex INTEGER UNSIGNED NOT NULL,
+   JobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
+   PathId INTEGER UNSIGNED REFERENCES Path NOT NULL,
+   Filename TEXT NOT NULL DEFAULT '',
+   DeltaSeq SMALLINT UNSIGNED DEFAULT 0,
+   MarkId INTEGER UNSIGNED DEFAULT 0,
+   LStat VARCHAR(255) NOT NULL,
+   MD5 VARCHAR(255) NOT NULL,
+   PRIMARY KEY(FileId) 
    );
-INSERT INTO new_Media (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) 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 TABLE Snapshot (
-  SnapshotId     INTEGER UNSIGNED AUTO_INCREMENT,
-  Name           TINYBLOB NOT NULL,
-  JobId          INTEGER UNSIGNED DEFAULT 0,
-  FileSetId INTEGER UNSIGNED DEFAULT 0,
-  CreateTDate    BIGINT   NOT NULL,
-  CreateDate     DATETIME NOT NULL,
-  ClientId       INTEGER DEFAULT 0,
-  Volume         TINYBLOB NOT NULL,
-  Device         TINYBLOB NOT NULL,
-  Type           TINYBLOB NOT NULL,
-  Retention      INTEGER DEFAULT 0,
-  Comment        BLOB,
-  primary key (SnapshotId)
-);
 
-CREATE UNIQUE INDEX snapshot_idx ON Snapshot (Device, Volume, Name);
+INSERT INTO file_temp (FileId, FileIndex, JobId, PathId, Filename, DeltaSeq,
+                      MarkId, LStat, Md5, llll)
+   SELECT FileId, FileIndex, JobId, PathId, Filename.Name, DeltaSeq, 
+         MarkId, LStat, Md5
+    FROM File JOIN Filename USING (FilenameId);
 
-CREATE INDEX jobtdate_idx on JobHisto (JobTDate);
+DROP TABLE File;
+DROP TABLE Filename;
 
-UPDATE Version SET VersionId=15;
-COMMIT;
+ALTER TABLE file_temp RENAME TO File;
 
-END-OF-DATA
+CREATE INDEX inx3 ON File (JobId);
+CREATE INDEX file_jpf_idx ON File (JobId, PathId, Filename);
 
-DBVERSION=15
+ALTER TABLE Job ADD COLUMN FileTable text default 'File';
+ALTER TABLE JobHisto ADD COLUMN FileTable text default 'File';
+UPDATE Version SET VersionId = 1016;
+commit;
+END-OF-DATA
+DBVERSION=1016
+fi
 
+if [ "$DBVERSION" = 1016 ] ; then
+    sqlite3 $* ${db_name}.db  <<END-OF-DATA
+ALTER TABLE Snapshot ADD COLUMN JobId integer default 0;
+ALTER TABLE Snapshot ADD COLUMN FileSetId integer default 0;
+UPDATE Version SET VersionId=1017;
+END-OF-DATA
+DBVERSION=1017
 fi
 
-if [ "$DBVERSION" -eq 15 ] ; then
+if [ "$DBVERSION" = 1017 ] ; then
     sqlite3 $* ${db_name}.db  <<END-OF-DATA
-    
-BEGIN;
+CREATE TABLE FileMedia
+(
+    JobId            integer     not null,
+    FileIndex        integer     not null,
+    MediaId          integer     not null,
+    BlockAddress      bigint     default 0,
+    RecordNo         integer     default 0,
+    FileOffset       bigint      default 0
+);
+CREATE INDEX file_media_idx on FileMedia (JobId, FileIndex);
+UPDATE Version SET VersionId=1018;
+END-OF-DATA
+DBVERSION=1018
+fi
+
+if [ "$DBVERSION" -eq 1018 ] ; then
+    if sqlite3 -f - -d ${db_name} $* <<END-OF-DATA
+begin;
 CREATE TABLE basefiles_temp (
    BaseId BIGINT,
    BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL,
@@ -181,90 +176,89 @@ INSERT INTO basefiles_temp (BaseId, BaseJobId, JobId,
    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 INTEGER UNSIGNED DEFAULT 0,
-   VolCloudParts INTEGER 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);
+DROP TABLE BaseFiles;
+ALTER TABLE basefiles_temp RENAME TO BaseFiles;
 
-CREATE UNIQUE INDEX Media_Volumename_Id ON Media (VolumeName);
+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;
 
+UPDATE Version SET VersionId=1019;
+commit;
+END-OF-DATA
+    then
+       echo "Update of Bacula SQLite3 tables 1018 to 1019 succeeded."
+       getVersion
+    else
+       echo "Update of Bacula SQLite3 tables 1018 to 1019 failed."
+       exit 1
+    fi
+fi
 
-DROP TABLE BaseFiles;
-ALTER TABLE basefiles_temp RENAME TO BaseFiles;
+if [ "$DBVERSION" -eq 1019 ] ; then
+    if sqlite3 -f - -d ${db_name} $* <<END-OF-DATA
+begin;
+ALTER TABLE Pool ADD COLUMN MaxPoolBytes BIGINT DEFAULT 0;
+ALTER TABLE Job ADD COLUMN PriorJob VARCHAR(128) DEFAULT '';
+ALTER TABLE JobHisto ADD COLUMN PriorJob VARCHAR(128) DEFAULT '';
+UPDATE Version SET VersionId=1020;
+commit;
+END-OF-DATA
+    then
+       echo "Update of Bacula SQLite3 tables 1019 to 1020 succeeded."
+       getVersion
+    else
+       echo "Update of Bacula SQLite3 tables 1019 to 1020 failed."
+       exit 1
+    fi
+fi
 
-CREATE INDEX job_jobtdate_inx ON job (JobTDate);
-ALTER TABLE Pool         ADD COLUMN CacheRetention BIGINT DEFAULT 0;
+if [ "$DBVERSION" -eq 1020 ] ; then
+    if sqlite3 -f - -d ${db_name} $* <<END-OF-DATA
+begin;
 ALTER TABLE File         MODIFY FileIndex INTEGER DEFAULT 0;
 ALTER TABLE RestoreObject MODIFY FileIndex INTEGER DEFAULT 0;
 ALTER TABLE BaseFiles    MODIFY FileIndex INTEGER DEFAULT 0;
-
-
-UPDATE Version SET VersionId=16;
-COMMIT;
-
+UPDATE Version SET VersionId=1021;
+commit;
 END-OF-DATA
-
-DBVERSION=16
-
+    then
+       echo "Update of Bacula SQLite3 tables 1020 to 1021 succeeded."
+       getVersion
+    else
+       echo "Update of Bacula SQLite3 tables 1020 to 1021 failed."
+       exit 1
+    fi
 fi
 
-echo ""
+if [ "$DBVERSION" -eq 1021 ] ; then
+    if sqlite3 -f - -d ${db_name} $* <<END-OF-DATA
+begin;
+CREATE TABLE Events
+(
+    EventsId          INTEGER,
+    EventsCode        text        not null,
+    EventsType       text        not null,
+    EventsTime       DATETIME,
+    EventsInsertTime  DATETIME DEFAULT current_timestamp,
+    EventsDaemon        text        default '',
+    EventsSource      text        default '',
+    EventsRef         text        default '',
+    EventsText       text        not null,
+    primary key (EventsId)
+);
+create index events_time_idx on Events (EventsTime);
 
-echo "WARNING: !!!! SQLite3 is no longer supported. !!!!"
-echo "WARNING: !!!! Please switch to MySQL or PostgreSQL !!!!"
-echo "WARNING: !!!!  as soon as possible. !!!!"
-echo ""
+UPDATE Version SET VersionId=1022;
+commit;
+END-OF-DATA
+    then
+       echo "Update of Bacula SQLite3 tables 1020 to 1021 succeeded."
+       getVersion
+    else
+       echo "Update of Bacula SQLite3 tables 1020 to 1021 failed."
+       exit 1
+    fi
+fi