3 # shell script to update SQLite from version 2.0 to 3.0
6 echo "This script will update a Bacula SQLite database from version 10 to 11"
7 echo " which is needed to convert from Bacula version 2.0.x to 3.0.x or higher"
8 echo "Depending on the size of your database,"
9 echo "this script may take several minutes to run."
17 ${bindir}/${sqlite} $* ${db_name}.db <<END-OF-DATA
19 -- ALTER TABLE Job ADD COLUMN (ReadBytes BIGINT UNSIGNED DEFAULT 0);
22 CREATE TEMPORARY TABLE job_backup AS SELECT * FROM Job;
28 Job VARCHAR(128) NOT NULL,
29 Name VARCHAR(128) NOT NULL,
32 ClientId INTEGER REFERENCES Client DEFAULT 0,
33 JobStatus CHAR NOT NULL,
34 SchedTime DATETIME NOT NULL,
35 StartTime DATETIME DEFAULT 0,
36 EndTime DATETIME DEFAULT 0,
37 RealEndTime DATETIME DEFAULT 0,
38 JobTDate BIGINT UNSIGNED DEFAULT 0,
39 VolSessionId INTEGER UNSIGNED DEFAULT 0,
40 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
41 JobFiles INTEGER UNSIGNED DEFAULT 0,
42 JobBytes BIGINT UNSIGNED DEFAULT 0,
43 ReadBytes BIGINT UNSIGNED DEFAULT 0,
44 JobErrors INTEGER UNSIGNED DEFAULT 0,
45 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
46 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
47 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
48 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
49 PurgedFiles TINYINT DEFAULT 0,
50 HasBase TINYINT DEFAULT 0,
53 CREATE INDEX inx6 ON Job (Name);
55 INSERT INTO Job (JobId, Job, Name, Type, Level, ClientId, JobStatus,
56 SchedTime, StartTime, EndTime, RealEndTime, JobTDate, VolSessionId,
57 VolSessionTime, JobFiles, JobBytes, JobErrors, JobMissingFiles,
58 PoolId, FileSetId, PriorJobId, PurgedFiles, HasBase) SELECT
59 JobId, Job, Name, Type, Level, ClientId, JobStatus, SchedTime, StartTime,
60 EndTime, RealEndTime, JobTDate, VolSessionId, VolSessionTime, JobFiles,
61 JobBytes, JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId,
62 PurgedFiles, HasBase FROM Job_backup;
64 DROP TABLE Job_backup;
67 -- ----------------------------------------------------------------
68 -- New ActionOnPurge field
70 CREATE TEMPORARY TABLE pool_backup AS SELECT * FROM Pool;
75 Name VARCHAR(128) NOT NULL,
76 NumVols INTEGER UNSIGNED DEFAULT 0,
77 MaxVols INTEGER UNSIGNED DEFAULT 0,
78 UseOnce TINYINT DEFAULT 0,
79 UseCatalog TINYINT DEFAULT 1,
80 AcceptAnyVolume TINYINT DEFAULT 0,
81 VolRetention BIGINT UNSIGNED DEFAULT 0,
82 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
83 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
84 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
85 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
86 AutoPrune TINYINT DEFAULT 0,
87 Recycle TINYINT DEFAULT 0,
88 ActionOnPurge TINYINT DEFAULT 0,
89 PoolType VARCHAR(20) NOT NULL,
90 LabelType TINYINT DEFAULT 0,
91 LabelFormat VARCHAR(128) NOT NULL,
92 Enabled TINYINT DEFAULT 1,
93 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
94 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
95 NextPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
96 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
97 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
98 MigrationTime BIGINT UNSIGNED DEFAULT 0,
103 INSERT INTO Pool (PoolId, Name, NumVols, MaxVols, UseOnce, UseCatalog,
104 AcceptAnyVolume, VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles,
105 MaxVolBytes, AutoPrune, Recycle, PoolType, LabelType,
106 LabelFormat, Enabled, ScratchPoolId, RecyclePoolId, NextPoolId,
107 MigrationHighBytes, MigrationLowBytes, MigrationTime)
108 SELECT PoolId, Name, NumVols, MaxVols, UseOnce, UseCatalog, AcceptAnyVolume,
109 VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles, MaxVolBytes, AutoPrune,
110 Recycle, PoolType, LabelType, LabelFormat, Enabled,
111 ScratchPoolId, RecyclePoolId, NextPoolId, MigrationHighBytes,
112 MigrationLowBytes, MigrationTime FROM pool_backup;
114 DROP TABLE pool_backup;
116 -- ----------------------------------------------------------------
117 -- New ActionOnPurge field
119 CREATE TEMPORARY TABLE media_backup AS SELECT * FROM Media;
124 VolumeName VARCHAR(128) NOT NULL,
125 Slot INTEGER DEFAULT 0,
126 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
127 MediaType VARCHAR(128) NOT NULL,
128 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
129 LabelType TINYINT DEFAULT 0,
130 FirstWritten DATETIME DEFAULT 0,
131 LastWritten DATETIME DEFAULT 0,
132 LabelDate DATETIME DEFAULT 0,
133 VolJobs INTEGER UNSIGNED DEFAULT 0,
134 VolFiles INTEGER UNSIGNED DEFAULT 0,
135 VolBlocks INTEGER UNSIGNED DEFAULT 0,
136 VolMounts INTEGER UNSIGNED DEFAULT 0,
137 VolBytes BIGINT UNSIGNED DEFAULT 0,
138 VolParts INTEGER UNSIGNED DEFAULT 0,
139 VolErrors INTEGER UNSIGNED DEFAULT 0,
140 VolWrites INTEGER UNSIGNED DEFAULT 0,
141 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
142 VolStatus VARCHAR(20) NOT NULL,
143 Enabled TINYINT DEFAULT 1,
144 Recycle TINYINT DEFAULT 0,
145 ActionOnPurge TINYINT DEFAULT 0,
146 VolRetention BIGINT UNSIGNED DEFAULT 0,
147 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
148 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
149 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
150 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
151 InChanger TINYINT DEFAULT 0,
152 StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
153 DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
154 MediaAddressing TINYINT DEFAULT 0,
155 VolReadTime BIGINT UNSIGNED DEFAULT 0,
156 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
157 EndFile INTEGER UNSIGNED DEFAULT 0,
158 EndBlock INTEGER UNSIGNED DEFAULT 0,
159 LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
160 RecycleCount INTEGER UNSIGNED DEFAULT 0,
161 InitialWrite DATETIME DEFAULT 0,
162 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
163 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
168 CREATE INDEX inx8 ON Media (PoolId);
171 MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId,
172 LabelType, FirstWritten, LastWritten, LabelDate, VolJobs,
173 VolFiles, VolBlocks, VolMounts, VolBytes, VolParts, VolErrors,
174 VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle,
175 VolRetention, VolUseDuration, MaxVolJobs,
176 MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId,
177 MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock,
178 LocationId, RecycleCount, InitialWrite, ScratchPoolId,
179 RecyclePoolId, Comment)
180 SELECT MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId,
181 LabelType, FirstWritten, LastWritten, LabelDate, VolJobs,
182 VolFiles, VolBlocks, VolMounts, VolBytes, VolParts, VolErrors,
183 VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle,
184 VolRetention, VolUseDuration, MaxVolJobs,
185 MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId,
186 MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock,
187 LocationId, RecycleCount, InitialWrite, ScratchPoolId,
188 RecyclePoolId, Comment FROM media_backup;
190 DROP TABLE media_backup;
192 UPDATE Version SET VersionId=11;
195 -- If you have already this table, you can remove it with:
196 -- DROP TABLE JobHistory;
198 -- Create a table like Job for long term statistics
199 CREATE TABLE JobHisto (
201 Job VARCHAR(128) NOT NULL,
202 Name VARCHAR(128) NOT NULL,
205 ClientId INTEGER REFERENCES Client DEFAULT 0,
206 JobStatus CHAR NOT NULL,
207 SchedTime DATETIME NOT NULL,
208 StartTime DATETIME DEFAULT 0,
209 EndTime DATETIME DEFAULT 0,
210 RealEndTime DATETIME DEFAULT 0,
211 JobTDate BIGINT UNSIGNED DEFAULT 0,
212 VolSessionId INTEGER UNSIGNED DEFAULT 0,
213 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
214 JobFiles INTEGER UNSIGNED DEFAULT 0,
215 JobBytes BIGINT UNSIGNED DEFAULT 0,
216 ReadBytes BIGINT UNSIGNED DEFAULT 0,
217 JobErrors INTEGER UNSIGNED DEFAULT 0,
218 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
219 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
220 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
221 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
222 PurgedFiles TINYINT DEFAULT 0,
223 HasBase TINYINT DEFAULT 0
225 CREATE INDEX inx61 ON JobHisto (StartTime);