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
20 CREATE TEMPORARY TABLE job_backup AS SELECT * FROM Job;
26 Job VARCHAR(128) NOT NULL,
27 Name VARCHAR(128) NOT NULL,
30 ClientId INTEGER REFERENCES Client DEFAULT 0,
31 JobStatus CHAR NOT NULL,
32 SchedTime DATETIME NOT NULL,
33 StartTime DATETIME DEFAULT 0,
34 EndTime DATETIME DEFAULT 0,
35 RealEndTime DATETIME DEFAULT 0,
36 JobTDate BIGINT UNSIGNED DEFAULT 0,
37 VolSessionId INTEGER UNSIGNED DEFAULT 0,
38 VolSessionTime INTEGER UNSIGNED DEFAULT 0,
39 JobFiles INTEGER UNSIGNED DEFAULT 0,
40 JobBytes BIGINT UNSIGNED DEFAULT 0,
41 ReadBytes BIGINT UNSIGNED DEFAULT 0,
42 JobErrors INTEGER UNSIGNED DEFAULT 0,
43 JobMissingFiles INTEGER UNSIGNED DEFAULT 0,
44 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
45 FileSetId INTEGER UNSIGNED REFERENCES FileSet DEFAULT 0,
46 PriorJobId INTEGER UNSIGNED REFERENCES Job DEFAULT 0,
47 PurgedFiles TINYINT DEFAULT 0,
48 HasBase TINYINT DEFAULT 0,
51 CREATE INDEX inx6 ON Job (Name);
53 INSERT INTO Job (JobId, Job, Name, Type, Level, ClientId, JobStatus,
54 SchedTime, StartTime, EndTime, RealEndTime, JobTDate, VolSessionId,
55 VolSessionTime, JobFiles, JobBytes, JobErrors, JobMissingFiles,
56 PoolId, FileSetId, PriorJobId, PurgedFiles, HasBase) SELECT
57 JobId, Job, Name, Type, Level, ClientId, JobStatus, SchedTime, StartTime,
58 EndTime, RealEndTime, JobTDate, VolSessionId, VolSessionTime, JobFiles,
59 JobBytes, JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId,
60 PurgedFiles, HasBase FROM Job_backup;
62 DROP TABLE Job_backup;
64 -- ----------------------------------------------------------------
65 -- New ActionOnPurge field
67 CREATE TEMPORARY TABLE pool_backup AS SELECT * FROM Pool;
72 Name VARCHAR(128) NOT NULL,
73 NumVols INTEGER UNSIGNED DEFAULT 0,
74 MaxVols INTEGER UNSIGNED DEFAULT 0,
75 UseOnce TINYINT DEFAULT 0,
76 UseCatalog TINYINT DEFAULT 1,
77 AcceptAnyVolume TINYINT DEFAULT 0,
78 VolRetention BIGINT UNSIGNED DEFAULT 0,
79 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
80 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
81 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
82 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
83 AutoPrune TINYINT DEFAULT 0,
84 Recycle TINYINT DEFAULT 0,
85 ActionOnPurge TINYINT DEFAULT 0,
86 PoolType VARCHAR(20) NOT NULL,
87 LabelType TINYINT DEFAULT 0,
88 LabelFormat VARCHAR(128) NOT NULL,
89 Enabled TINYINT DEFAULT 1,
90 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
91 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
92 NextPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
93 MigrationHighBytes BIGINT UNSIGNED DEFAULT 0,
94 MigrationLowBytes BIGINT UNSIGNED DEFAULT 0,
95 MigrationTime BIGINT UNSIGNED DEFAULT 0,
100 INSERT INTO Pool (PoolId, Name, NumVols, MaxVols, UseOnce, UseCatalog,
101 AcceptAnyVolume, VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles,
102 MaxVolBytes, AutoPrune, Recycle, PoolType, LabelType,
103 LabelFormat, Enabled, ScratchPoolId, RecyclePoolId, NextPoolId,
104 MigrationHighBytes, MigrationLowBytes, MigrationTime)
105 SELECT PoolId, Name, NumVols, MaxVols, UseOnce, UseCatalog, AcceptAnyVolume,
106 VolRetention, VolUseDuration, MaxVolJobs, MaxVolFiles, MaxVolBytes, AutoPrune,
107 Recycle, PoolType, LabelType, LabelFormat, Enabled,
108 ScratchPoolId, RecyclePoolId, NextPoolId, MigrationHighBytes,
109 MigrationLowBytes, MigrationTime FROM pool_backup;
111 DROP TABLE pool_backup;
113 -- ----------------------------------------------------------------
114 -- New ActionOnPurge field
116 CREATE TEMPORARY TABLE media_backup AS SELECT * FROM Media;
121 VolumeName VARCHAR(128) NOT NULL,
122 Slot INTEGER DEFAULT 0,
123 PoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
124 MediaType VARCHAR(128) NOT NULL,
125 MediaTypeId INTEGER UNSIGNED REFERENCES MediaType DEFAULT 0,
126 LabelType TINYINT DEFAULT 0,
127 FirstWritten DATETIME DEFAULT 0,
128 LastWritten DATETIME DEFAULT 0,
129 LabelDate DATETIME DEFAULT 0,
130 VolJobs INTEGER UNSIGNED DEFAULT 0,
131 VolFiles INTEGER UNSIGNED DEFAULT 0,
132 VolBlocks INTEGER UNSIGNED DEFAULT 0,
133 VolMounts INTEGER UNSIGNED DEFAULT 0,
134 VolBytes BIGINT UNSIGNED DEFAULT 0,
135 VolParts INTEGER UNSIGNED DEFAULT 0,
136 VolErrors INTEGER UNSIGNED DEFAULT 0,
137 VolWrites INTEGER UNSIGNED DEFAULT 0,
138 VolCapacityBytes BIGINT UNSIGNED DEFAULT 0,
139 VolStatus VARCHAR(20) NOT NULL,
140 Enabled TINYINT DEFAULT 1,
141 Recycle TINYINT DEFAULT 0,
142 ActionOnPurge TINYINT DEFAULT 0,
143 VolRetention BIGINT UNSIGNED DEFAULT 0,
144 VolUseDuration BIGINT UNSIGNED DEFAULT 0,
145 MaxVolJobs INTEGER UNSIGNED DEFAULT 0,
146 MaxVolFiles INTEGER UNSIGNED DEFAULT 0,
147 MaxVolBytes BIGINT UNSIGNED DEFAULT 0,
148 InChanger TINYINT DEFAULT 0,
149 StorageId INTEGER UNSIGNED REFERENCES Storage DEFAULT 0,
150 DeviceId INTEGER UNSIGNED REFERENCES Device DEFAULT 0,
151 MediaAddressing TINYINT DEFAULT 0,
152 VolReadTime BIGINT UNSIGNED DEFAULT 0,
153 VolWriteTime BIGINT UNSIGNED DEFAULT 0,
154 EndFile INTEGER UNSIGNED DEFAULT 0,
155 EndBlock INTEGER UNSIGNED DEFAULT 0,
156 LocationId INTEGER UNSIGNED REFERENCES Location DEFAULT 0,
157 RecycleCount INTEGER UNSIGNED DEFAULT 0,
158 InitialWrite DATETIME DEFAULT 0,
159 ScratchPoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
160 RecyclePoolId INTEGER UNSIGNED REFERENCES Pool DEFAULT 0,
165 CREATE INDEX inx8 ON Media (PoolId);
168 MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId,
169 LabelType, FirstWritten, LastWritten, LabelDate, VolJobs,
170 VolFiles, VolBlocks, VolMounts, VolBytes, VolParts, VolErrors,
171 VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle,
172 VolRetention, VolUseDuration, MaxVolJobs,
173 MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId,
174 MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock,
175 LocationId, RecycleCount, InitialWrite, ScratchPoolId,
176 RecyclePoolId, Comment)
177 SELECT MediaId, VolumeName, Slot, PoolId, MediaType, MediaTypeId,
178 LabelType, FirstWritten, LastWritten, LabelDate, VolJobs,
179 VolFiles, VolBlocks, VolMounts, VolBytes, VolParts, VolErrors,
180 VolWrites, VolCapacityBytes, VolStatus, Enabled, Recycle,
181 VolRetention, VolUseDuration, MaxVolJobs,
182 MaxVolFiles, MaxVolBytes, InChanger, StorageId, DeviceId,
183 MediaAddressing, VolReadTime, VolWriteTime, EndFile, EndBlock,
184 LocationId, RecycleCount, InitialWrite, ScratchPoolId,
185 RecyclePoolId, Comment FROM media_backup;
187 DROP TABLE media_backup;
189 -- ----------------------------------------------------------------
191 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);