2 \chapter{Migration and Copy}
3 \label{MigrationChapter}
4 \index[general]{Migration}
7 The term Migration, as used in the context of Bacula, means moving data from
8 one Volume to another. In particular it refers to a Job (similar to a backup
9 job) that reads data that was previously backed up to a Volume and writes
10 it to another Volume. As part of this process, the File catalog records
11 associated with the first backup job are purged. In other words, Migration
12 moves Bacula Job data from one Volume to another by reading the Job data
13 from the Volume it is stored on, writing it to a different Volume in a
14 different Pool, and then purging the database records for the first Job.
16 The Copy process is essentially identical to the Migration feature
17 with the exception that the Job that is copied is left unchanged. This
18 essentially creates two identical copies of the same backup. The Copy Job runs
19 without using the File daemon by copying the data from the old backup Volume to
20 a different Volume in a different Pool.
22 The section process for which Job or Jobs are migrated
23 can be based on quite a number of different criteria such as:
25 \item a single previous Job
28 \item a regular expression matching a Job, Volume, or Client name
29 \item the time a Job has been on a Volume
30 \item high and low water marks (usage or occupation) of a Pool
34 The details of these selection criteria will be defined below.
36 To run a Migration job, you must first define a Job resource very similar
37 to a Backup Job but with {\bf Type = Migrate} instead of {\bf Type =
38 Backup}. One of the key points to remember is that the Pool that is
39 specified for the migration job is the only pool from which jobs will
40 be migrated, with one exception noted below. In addition, the Pool to
41 which the selected Job or Jobs will be migrated is defined by the {\bf
42 Next Pool = ...} in the Pool resource specified for the Migration Job.
44 Bacula permits pools to contain Volumes with different Media Types.
45 However, when doing migration, this is a very undesirable condition. For
46 migration to work properly, you should use pools containing only Volumes of
47 the same Media Type for all migration jobs.
49 The migration job normally is either manually started or starts
50 from a Schedule much like a backup job. It searches
51 for a previous backup Job or Jobs that match the parameters you have
52 specified in the migration Job resource, primarily a {\bf Selection Type}
53 (detailed a bit later). Then for
54 each previous backup JobId found, the Migration Job will run a new Job which
55 copies the old Job data from the previous Volume to a new Volume in
56 the Migration Pool. It is possible that no prior Jobs are found for
57 migration, in which case, the Migration job will simply terminate having
58 done nothing, but normally at a minimum, three jobs are involved during a
62 \item The currently running Migration control Job. This is only
63 a control job for starting the migration child jobs.
64 \item The previous Backup Job (already run). The File records
65 for this Job are purged if the Migration job successfully
66 terminates. The original data remains on the Volume until
67 it is recycled and rewritten.
68 \item A new Migration Backup Job that moves the data from the
69 previous Backup job to the new Volume. If you subsequently
70 do a restore, the data will be read from this Job.
73 If the Migration control job finds a number of JobIds to migrate (e.g.
74 it is asked to migrate one or more Volumes), it will start one new
75 migration backup job for each JobId found on the specified Volumes.
76 Please note that Migration doesn't scale too well since Migrations are
77 done on a Job by Job basis. This if you select a very large volume or
78 a number of volumes for migration, you may have a large number of
79 Jobs that start. Because each job must read the same Volume, they will
80 run consecutively (not simultaneously).
82 \section{Migration and Copy Job Resource Directives}
84 The following directives can appear in a Director's Job resource, and they
85 are used to define a Migration job.
88 \item [Pool = \lt{}Pool-name\gt{}] The Pool specified in the Migration
89 control Job is not a new directive for the Job resource, but it is
90 particularly important because it determines what Pool will be examined for
91 finding JobIds to migrate. The exception to this is when {\bf Selection
92 Type = SQLQuery}, in which case no Pool is used, unless you
93 specifically include it in the SQL query. Note, the Pool resource
94 referenced must contain a {\bf Next Pool = ...} directive to define
95 the Pool to which the data will be migrated.
97 \item [Type = Migrate]
98 {\bf Migrate} is a new type that defines the job that is run as being a
99 Migration Job. A Migration Job is a sort of control job and does not have
100 any Files associated with it, and in that sense they are more or less like
101 an Admin job. Migration jobs simply check to see if there is anything to
102 Migrate then possibly start and control new Backup jobs to migrate the data
103 from the specified Pool to another Pool.
106 {\bf Copy} is a new type that defines the job that is run as being a
107 Copy Job. A Copy Job is a sort of control job and does not have
108 any Files associated with it, and in that sense they are more or less like
109 an Admin job. Copy jobs simply check to see if there is anything to
110 Copy then possibly start and control new Backup jobs to copy the data
111 from the specified Pool to another Pool.
113 \item [Selection Type = \lt{}Selection-type-keyword\gt{}]
114 The \lt{}Selection-type-keyword\gt{} determines how the migration job
115 will go about selecting what JobIds to migrate. In most cases, it is
116 used in conjunction with a {\bf Selection Pattern} to give you fine
117 control over exactly what JobIds are selected. The possible values
118 for \lt{}Selection-type-keyword\gt{} are:
120 \item [SmallestVolume] This selection keyword selects the volume with the
121 fewest bytes from the Pool to be migrated. The Pool to be migrated
122 is the Pool defined in the Migration Job resource. The migration
123 control job will then start and run one migration backup job for
124 each of the Jobs found on this Volume. The Selection Pattern, if
125 specified, is not used.
127 \item [OldestVolume] This selection keyword selects the volume with the
128 oldest last write time in the Pool to be migrated. The Pool to be
129 migrated is the Pool defined in the Migration Job resource. The
130 migration control job will then start and run one migration backup
131 job for each of the Jobs found on this Volume. The Selection
132 Pattern, if specified, is not used.
134 \item [Client] The Client selection type, first selects all the Clients
135 that have been backed up in the Pool specified by the Migration
136 Job resource, then it applies the {\bf Selection Pattern} (defined
137 below) as a regular expression to the list of Client names, giving
138 a filtered Client name list. All jobs that were backed up for those
139 filtered (regexed) Clients will be migrated.
140 The migration control job will then start and run one migration
141 backup job for each of the JobIds found for those filtered Clients.
143 \item [Volume] The Volume selection type, first selects all the Volumes
144 that have been backed up in the Pool specified by the Migration
145 Job resource, then it applies the {\bf Selection Pattern} (defined
146 below) as a regular expression to the list of Volume names, giving
147 a filtered Volume list. All JobIds that were backed up for those
148 filtered (regexed) Volumes will be migrated.
149 The migration control job will then start and run one migration
150 backup job for each of the JobIds found on those filtered Volumes.
152 \item [Job] The Job selection type, first selects all the Jobs (as
153 defined on the {\bf Name} directive in a Job resource)
154 that have been backed up in the Pool specified by the Migration
155 Job resource, then it applies the {\bf Selection Pattern} (defined
156 below) as a regular expression to the list of Job names, giving
157 a filtered Job name list. All JobIds that were run for those
158 filtered (regexed) Job names will be migrated. Note, for a given
159 Job named, they can be many jobs (JobIds) that ran.
160 The migration control job will then start and run one migration
161 backup job for each of the Jobs found.
163 \item [SQLQuery] The SQLQuery selection type, used the {\bf Selection
164 Pattern} as an SQL query to obtain the JobIds to be migrated.
165 The Selection Pattern must be a valid SELECT SQL statement for your
166 SQL engine, and it must return the JobId as the first field
169 \item [PoolOccupancy] This selection type will cause the Migration job
170 to compute the total size of the specified pool for all Media Types
171 combined. If it exceeds the {\bf Migration High Bytes} defined in
172 the Pool, the Migration job will migrate all JobIds beginning with
173 the oldest Volume in the pool (determined by Last Write time) until
174 the Pool bytes drop below the {\bf Migration Low Bytes} defined in the
175 Pool. This calculation should be consider rather approximative because
176 it is made once by the Migration job before migration is begun, and
177 thus does not take into account additional data written into the Pool
178 during the migration. In addition, the calculation of the total Pool
179 byte size is based on the Volume bytes saved in the Volume (Media)
181 entries. The bytes calculate for Migration is based on the value stored
182 in the Job records of the Jobs to be migrated. These do not include the
183 Storage daemon overhead as is in the total Pool size. As a consequence,
184 normally, the migration will migrate more bytes than strictly necessary.
186 \item [PoolTime] The PoolTime selection type will cause the Migration job to
187 look at the time each JobId has been in the Pool since the job ended.
188 All Jobs in the Pool longer than the time specified on {\bf Migration Time}
189 directive in the Pool resource will be migrated.
192 \item [Selection Pattern = \lt{}Quoted-string\gt{}]
193 The Selection Patterns permitted for each Selection-type-keyword are
196 For the OldestVolume and SmallestVolume, this
197 Selection pattern is not used (ignored).
199 For the Client, Volume, and Job
200 keywords, this pattern must be a valid regular expression that will filter
201 the appropriate item names found in the Pool.
203 For the SQLQuery keyword, this pattern must be a valid SELECT SQL statement
208 \section{Migration Pool Resource Directives}
210 The following directives can appear in a Director's Pool resource, and they
211 are used to define a Migration job.
214 \item [Migration Time = \lt{}time-specification\gt{}]
215 If a PoolTime migration is done, the time specified here in seconds (time
216 modifiers are permitted -- e.g. hours, ...) will be used. If the
217 previous Backup Job or Jobs selected have been in the Pool longer than
218 the specified PoolTime, then they will be migrated.
220 \item [Migration High Bytes = \lt{}byte-specification\gt{}]
221 This directive specifies the number of bytes in the Pool which will
222 trigger a migration if a {\bf PoolOccupancy} migration selection
223 type has been specified. The fact that the Pool
224 usage goes above this level does not automatically trigger a migration
225 job. However, if a migration job runs and has the PoolOccupancy selection
226 type set, the Migration High Bytes will be applied. Bacula does not
227 currently restrict a pool to have only a single Media Type, so you
228 must keep in mind that if you mix Media Types in a Pool, the results
229 may not be what you want, as the Pool count of all bytes will be
230 for all Media Types combined.
232 \item [Migration Low Bytes = \lt{}byte-specification\gt{}]
233 This directive specifies the number of bytes in the Pool which will
234 stop a migration if a {\bf PoolOccupancy} migration selection
235 type has been specified and triggered by more than Migration High
236 Bytes being in the pool. In other words, once a migration job
237 is started with {\bf PoolOccupancy} migration selection and it
238 determines that there are more than Migration High Bytes, the
239 migration job will continue to run jobs until the number of
240 bytes in the Pool drop to or below Migration Low Bytes.
242 \item [Next Pool = \lt{}pool-specification\gt{}]
243 The Next Pool directive specifies the pool to which Jobs will be
244 migrated. This directive is required to define the Pool into which
245 the data will be migrated. Without this directive, the migration job
246 will terminate in error.
248 \item [Storage = \lt{}storage-specification\gt{}]
249 The Storage directive specifies what Storage resource will be used
250 for all Jobs that use this Pool. It takes precedence over any other
251 Storage specifications that may have been given such as in the
252 Schedule Run directive, or in the Job resource. We highly recommend
253 that you define the Storage resource to be used in the Pool rather
254 than elsewhere (job, schedule run, ...).
257 \section{Important Migration Considerations}
258 \index[general]{Important Migration Considerations}
260 \item Each Pool into which you migrate Jobs or Volumes {\bf must}
261 contain Volumes of only one Media Type.
263 \item Migration takes place on a JobId by JobId basis. That is
264 each JobId is migrated in its entirety and independently
265 of other JobIds. Once the Job is migrated, it will be
266 on the new medium in the new Pool, but for the most part,
267 aside from having a new JobId, it will appear with all the
268 same characteristics of the original job (start, end time, ...).
269 The column RealEndTime in the catalog Job table will contain the
270 time and date that the Migration terminated, and by comparing
271 it with the EndTime column you can tell whether or not the
272 job was migrated. The original job is purged of its File
273 records, and its Type field is changed from "B" to "M" to
274 indicate that the job was migrated.
276 \item Jobs on Volumes will be Migration only if the Volume is
277 marked, Full, Used, or Error. Volumes that are still
278 marked Append will not be considered for migration. This
279 prevents Bacula from attempting to read the Volume at
280 the same time it is writing it. It also reduces other deadlock
281 situations, as well as avoids the problem that you migrate a
282 Volume and later find new files appended to that Volume.
284 \item As noted above, for the Migration High Bytes, the calculation
285 of the bytes to migrate is somewhat approximate.
287 \item If you keep Volumes of different Media Types in the same Pool,
288 it is not clear how well migration will work. We recommend only
289 one Media Type per pool.
291 \item It is possible to get into a resource deadlock where Bacula does
292 not find enough drives to simultaneously read and write all the
293 Volumes needed to do Migrations. For the moment, you must take
294 care as all the resource deadlock algorithms are not yet implemented.
296 \item Migration is done only when you run a Migration job. If you set a
297 Migration High Bytes and that number of bytes is exceeded in the Pool
298 no migration job will automatically start. You must schedule the
299 migration jobs, and they must run for any migration to take place.
301 \item If you migrate a number of Volumes, a very large number of Migration
304 \item Figuring out what jobs will actually be migrated can be a bit complicated
305 due to the flexibility provided by the regex patterns and the number of
306 different options. Turning on a debug level of 100 or more will provide
307 a limited amount of debug information about the migration selection
310 \item Bacula currently does only minimal Storage conflict resolution, so you
311 must take care to ensure that you don't try to read and write to the
312 same device or Bacula may block waiting to reserve a drive that it
313 will never find. In general, ensure that all your migration
314 pools contain only one Media Type, and that you always
315 migrate to pools with different Media Types.
317 \item The {\bf Next Pool = ...} directive must be defined in the Pool
318 referenced in the Migration Job to define the Pool into which the
319 data will be migrated.
321 \item Pay particular attention to the fact that data is migrated on a Job
322 by Job basis, and for any particular Volume, only one Job can read
323 that Volume at a time (no simultaneous read), so migration jobs that
324 all reference the same Volume will run sequentially. This can be a
325 potential bottle neck and does not scale very well to large numbers
328 \item Only migration of Selection Types of Job and Volume have
329 been carefully tested. All the other migration methods (time,
330 occupancy, smallest, oldest, ...) need additional testing.
332 \item Migration is only implemented for a single Storage daemon. You
333 cannot read on one Storage daemon and write on another.
337 \section{Example Migration Jobs}
338 \index[general]{Example Migration Jobs}
340 When you specify a Migration Job, you must specify all the standard
341 directives as for a Job. However, certain such as the Level, Client, and
342 FileSet, though they must be defined, are ignored by the Migration job
343 because the values from the original job used instead.
345 As an example, suppose you have the following Job that
346 you run every night. To note: there is no Storage directive in the
347 Job resource; there is a Storage directive in each of the Pool
348 resources; the Pool to be migrated (File) contains a Next Pool
349 directive that defines the output Pool (where the data is written
350 by the migration job).
354 # Define the backup Job
358 Level = Incremental # default
361 Schedule = "WeeklyCycle"
366 # Default pool definition
377 # Tape pool definition
386 # Definition of File storage device
390 Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9"
391 Device = "File" # same as Device in Storage daemon
392 Media Type = File # same as MediaType in Storage daemon
395 # Definition of DLT tape storage device
399 Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9"
400 Device = "HP DLT 80" # same as Device in Storage daemon
401 Media Type = DLT8000 # same as MediaType in Storage daemon
407 Where we have included only the essential information -- i.e. the
408 Director, FileSet, Catalog, Client, Schedule, and Messages resources are
411 As you can see, by running the NightlySave Job, the data will be backed up
412 to File storage using the Default pool to specify the Storage as File.
414 Now, if we add the following Job resource to this conf file.
419 Name = "migrate-volume"
426 Maximum Concurrent Jobs = 4
427 Selection Type = Volume
428 Selection Pattern = "File"
433 and then run the job named {\bf migrate-volume}, all volumes in the Pool
434 named Default (as specified in the migrate-volume Job that match the
435 regular expression pattern {\bf File} will be migrated to tape storage
436 DLTDrive because the {\bf Next Pool} in the Default Pool specifies that
437 Migrations should go to the pool named {\bf Tape}, which uses
438 Storage {\bf DLTDrive}.
440 If instead, we use a Job resource as follows:
452 Maximum Concurrent Jobs = 4
454 Selection Pattern = ".*Save"
459 All jobs ending with the name Save will be migrated from the File Default to
460 the Tape Pool, or from File storage to Tape storage.