bscan
The bscan
program can be used to re-create a database (catalog) records from
the backup information written to one or more Volumes. This is normally needed
only if one or more Volumes have been pruned or purged from your catalog so that
the records on the Volume are no longer in the catalog, or for Volumes that you
have archived. Note, if you scan in Volumes that were previously purged, you
will be able to do restores from those Volumes. However, unless you modify the
Job and File retention times for the Jobs that were added by scanning, the
next time you run any backup Job with the same name, the records will be pruned
again. Since it takes a long time to scan Volumes this can be very frustrating.
Recovered volume status is set to Archive and Volume Retention time is set to
one month by default for volumes that were restored this way.
With some care, bscan
can also be used to synchronize your existing catalog with a Volume.
Although we have never seen a case of bscan
damaging a catalog, since bscan
modifies
your catalog, we recommend that you do a simple ASCII backup of your database before
running bscan
just to be sure. See Compacting Your Database for the details of making
a copy of your database.
bscan
can also be useful in a disaster recovery situation, after the loss of a hard disk,
if you do not have a valid bootstrap file for reloading your system, or if a Volume has
been recycled but not overwritten, you can use bscan
to re-create your database, which can
then be used to restore your system or a file to its previous state.
bscan
Is also able to re-create/list records such as Restore Object and Plugin Objects.
It is called:
Usage: bscan [options] <bacula-archive>
-b bootstrap specify a bootstrap file
-c <file> specify configuration file
-d <nn> set debug level to nn
-m update media info in database
-n <name> specify the database name (default bacula)
-u <user> specify database user name (default bacula)
-P <password> specify database password (default none)
-h <host> specify database host (default NULL)
-p proceed inspite of I/O errors
-r list records
-s synchronize or store in database
-v verbose
-V <Volumes> specify Volume names (separated by |)
-w <dir> specify working directory (default from conf file)
-? print this message
If you are using MySQL or PostgreSQL, there is no need to supply a working directory since
in that case, bscan
knows where the databases are. However, if you have provided security
on your database, you may need to supply either the database name (-b option), the user
name (-u option), and/or the password (-p) options.
Note
before bscan
can work, it needs at least a bare bones valid database. If your database exists but some records are missing because they were pruned, then you are all set. If your database was lost or destroyed, then you must first ensure that you have the SQL program running ( or ), then you must create the Bacula database (normally named bacula), and you must create the Bacula tables using the scripts in the /opt/bacula/scripts/
directory. This is explained in the Installation chapter of the manual. Finally, before scanning into an empty database, you must start and stop the Director with the appropriate bacula-dir.conf file so that it can create the Client and Storage records which are not stored on the Volumes. Without these records, scanning is unable to connect the Job records to the proper client.
Forgetting for the moment the extra complications of a full rebuild of your catalog, let’s
suppose that you did a backup to Volumes “Vol001” and “Vol002”, then sometime later all
records of one or both those Volumes were pruned or purged from the database. By using bscan
you can recreate the catalog entries for those Volumes and then use the restore
command in
the Console to restore whatever you want. A command something like:
bscan -c bacula-sd.conf -v -V Vol001\|Vol002 /dev/nst0
will give you an idea of what is going to happen without changing your catalog. Of course, you may need to change the path to the Storage daemon’s conf file, the Volume name, and your tape (or disk) device name. This command must read the entire tape, so if it has a lot of data, it may take a long time, and thus you might want to immediately use the command listed below. Note, if you are writing to a disk file, replace the device name with the path to the directory that contains the Volumes. This must correspond to the Archive Device in the conf file.
Then to actually write or store the records in the catalog, add the -s option as follows:
bscan -s -m -c bacula-sd.conf -v -V Vol001\|Vol002 /dev/nst0
When writing to the database, if bscan
finds existing records, it will generally either
update them if something is wrong or leave them alone. Thus if the Volumes you are scanning
are all or partially in the catalog already, no harm will be done to that existing data.
Any missing data will simply be added.
If you have multiple tapes, you should scan them with:
bscan -s -m -c bacula-sd.conf -v -V Vol001\|Vol002\|Vol003 /dev/nst0
Since there is a limit on the command line length (511 bytes) accepted by bscan
, if you have too many Volumes, you will need to manually create a bootstrap file. See the Restoring Files with the Bootstrap File of the Bacula Enterprise Main manual, in particular the section entitled Bootstrap for bscan. Basically, the .bsr file for the above example might look like:
Volume=Vol001
Volume=Vol002
Volume=Vol003
Note: bscan
does not support supplying Volume names on the command line and at the same time in a bootstrap file. Please use only one or the other.
You should, always try to specify the tapes in the order they are written. If you do not, any Jobs that span a volume may not be fully or properly restored. However, bscan
can handle scanning tapes that are not sequential. Any incomplete records at the end of the tape will simply be ignored in that case. If you are simply repairing an existing catalog, this may be OK, but if you are creating a new catalog from scratch, it will leave your database in an incorrect state. If you do not specify all necessary Volumes on a single bscan
command, bscan
will not be able to correctly restore the records that span two volumes. In other words, it is much better to specify two or three volumes on a single bscan
command (or in a .bsr file) rather than run bscan
two or three times, each with a single volume.
Note, the restoration process using bscan
is not identical to the original creation of the catalog data. This is because certain data such as Client records and other non-essential data such as volume reads, volume mounts, etc is not stored on the Volume, and thus is not restored by bscan
. The results of bscanning are, however, perfectly valid, and will permit restoration of any or all the files in the catalog using the normal Bacula console commands. If you are starting with an empty catalog and expecting bscan
to reconstruct it, you may be a bit disappointed, but at a minimum, you must ensure that your bacula-dir.conf file is the same as what it previously was – that is, it must contain all the appropriate Client resources so that they will be recreated in your new database before running bscan
. Normally when the Director starts, it will recreate any missing Client records in the catalog. Another problem you will have is that even if the Volumes (Media records) are recreated in the database, they will not have their autochanger status and slots properly set. As a result, you will need to repair that by using the update slots
command. There may be other considerations as well. Rather than bscanning, you should always attempt to recover you previous catalog backup.
Using bscan to Compare Volume to Existing Catalog
If you wish to compare the contents of a Volume to an existing catalog without changing the catalog, you can safely do so if and only if you do not specify either the -m or the -s options in order to avoid modifying the catalog. However, not every record that is stored in the catalog is stored on the volumes, so we don’t particularly recommend using bscan other than for testing. Probably the best way to compare what is on a Volume to what is in the Catalog is to use one of the Verify Job options.
Using bscan to Recreate Catalog from Volume
This is the mode for which bscan
is most useful. You can either bscan
into a freshly
created catalog, or directly into your existing catalog (after having made an ASCII copy as
described above). Normally, you should start with a freshly created catalog that contains no data.
Starting with a single Volume named TestVolume1, you run a command such as:
./bscan -V TestVolume1 -v -s -m -c bacula-sd.conf /dev/nst0
If there is more than one volume, simply append it to the first one separating it with a vertical bar. You may need to precede the vertical bar with a forward slash escape the shell – e.g. TestVolume1\|TestVolume2. The -v option was added for verbose output (this can be omitted if desired). The -s option that tells bscan
to store information in the database. The physical device name /dev/nst0 is specified after all the options.
For example, after having done a full backup of a directory, then two incrementals, I reinitialized the SQLite database as described above, and using the bootstrap.bsr file noted above, I entered the following command:
./bscan -b bootstrap.bsr -v -s -c bacula-sd.conf /dev/nst0
which produced the following output:
bscan: bscan.c:182 Using Database: bacula, User: bacula
bscan: bscan.c:673 Created Pool record for Pool: Default
bscan: bscan.c:271 Pool type "Backup" is OK.
bscan: bscan.c:632 Created Media record for Volume: TestVolume1
bscan: bscan.c:298 Media type "DDS-4" is OK.
bscan: bscan.c:307 VOL_LABEL: OK for Volume: TestVolume1
bscan: bscan.c:693 Created Client record for Client: Rufus
bscan: bscan.c:769 Created new JobId=1 record for original JobId=2
bscan: bscan.c:717 Created FileSet record "Kerns Files"
bscan: bscan.c:819 Updated Job termination record for new JobId=1
bscan: bscan.c:905 Created JobMedia record JobId 1, MediaId 1
bscan: Got EOF on device /dev/nst0
bscan: bscan.c:693 Created Client record for Client: Rufus
bscan: bscan.c:769 Created new JobId=2 record for original JobId=3
bscan: bscan.c:708 Fileset "Kerns Files" already exists.
bscan: bscan.c:819 Updated Job termination record for new JobId=2
bscan: bscan.c:905 Created JobMedia record JobId 2, MediaId 1
bscan: Got EOF on device /dev/nst0
bscan: bscan.c:693 Created Client record for Client: Rufus
bscan: bscan.c:769 Created new JobId=3 record for original JobId=4
bscan: bscan.c:708 Fileset "Kerns Files" already exists.
bscan: bscan.c:819 Updated Job termination record for new JobId=3
bscan: bscan.c:905 Created JobMedia record JobId 3, MediaId 1
bscan: Got EOF on device /dev/nst0
bscan: bscan.c:652 Updated Media record at end of Volume: TestVolume1
bscan: bscan.c:428 End of Volume. VolFiles=3 VolBlocks=57 VolBytes=10,027,437
The key points to note are that bscan
prints a line when each major record is created. Due to the volume of output, it does not print a line for each file record unless you supply the -v option twice or more on the command line.
In the case of a Job record, the new JobId will not normally be the same as the original Jobid. For example, for the first JobId above, the new JobId is 1, but the original JobId is 2. This is nothing to be concerned about as it is the normal nature of databases. bscan
will keep everything straight.
Although bscan
claims that it created a Client record for Client: Rufus three times, it was actually only created the first time. This is normal.
You will also notice that it read an end of file after each Job (Got EOF
on device …). Finally the last line gives the total statistics for the bscan
.
If you had added a second -v option to the command line, Bacula would have been even more verbose, dumping virtually all the details of each Job record it encountered.
Now if you start Bacula and enter a list jobs command to the console program, you will get:
+-------+----------+------------------+------+-----+----------+----------+---------+
| JobId | Name | StartTime | Type | Lvl | JobFiles | JobBytes | JobStat |
+-------+----------+------------------+------+-----+----------+----------+---------+
| 1 | kernsave | 2002-10-07 14:59 | B | F | 84 | 4180207 | T |
| 2 | kernsave | 2002-10-07 15:00 | B | I | 15 | 2170314 | T |
| 3 | kernsave | 2002-10-07 15:01 | B | I | 33 | 3662184 | T |
+-------+----------+------------------+------+-----+----------+----------+---------+
which corresponds virtually identically with what the database contained before it was re-initialized and restored with bscan
. All the Jobs and Files found on the tape are restored including most of the Media record. The Volume (Media) records restored will be marked as Full so that they cannot be rewritten without operator intervention.
It should be noted that bscan
cannot restore a database to the exact condition it was in previously because a lot of the less important information contained in the database is not saved to the tape. Nevertheless, the reconstruction is sufficiently complete, that you can run restore
against it and get valid results.
An interesting aspect of restoring a catalog backup using bscan
is that the backup was made while Bacula was running and writing to a tape. At the point the backup of the catalog is made, the tape Bacula is writing to will have say 10 files on it, but after the catalog backup is made, there will be 11 files on the tape Bacula is writing. This there is a difference between what is contained in the backed up catalog and what is actually on the tape. If after restoring a catalog, you attempt to write on the same tape that was used to backup the catalog, Bacula will detect the difference in the number of files registered in the catalog compared to what is on the tape, and will mark the tape in error.
There are two solutions to this problem. The first is possibly the simplest and is to mark the volume as Used before doing any backups. The second is to manually correct the number of files listed in the Media record of the catalog. This procedure is documented elsewhere in the manual and involves using the update volume
command in bconsole
.
Using bscan to Correct Volume File Count
If the Storage daemon crashes during a backup Job, the catalog will not be properly updated for the Volume being used at the time of the crash. This means that the Storage daemon will have written say 20 files on the tape, but the catalog record for the Volume indicates only 19 files.
Bacula refuses to write on a tape that contains a different number of files from what is
in the catalog. To correct this situation, you may run a bscan
with the -m option
(but without the -s option) to update only the final Media record for the Volumes read.
After bscan
If you use bscan
to enter the contents of the Volume into an existing catalog, you should
be aware that the records you entered may be immediately pruned during the next job,
particularly if the Volume is very old or had been previously purged. To avoid this, after
running bscan
, you can manually set the volume status (VolStatus) to Read-Only by
using the update
command in the catalog. This will allow you to restore from the volume
without having it immediately purged. When you have restored and backed up the data, you can
reset the VolStatus to Used and the Volume will be purged from the catalog.
Go back to the Tape/Volume Management chapter.
Go back to the main Bacula Enterprise Management page.