Pages

Saturday, September 17, 2011

Reusing/relabeling media with bacula

A few weeks ago I reinstalled my backup server with bacula. I have a small machine (2x700MHz, 1GB, Solaris 10, Bacula 5.0.3) with 3 DDS-3 tape drives (and other stuff to play around). Now I want to reuse my old tapes which were already labeled. So I have to do some kind of relabeling. When I try to normally label the prior used tapes I get the following error: 

*label
The defined Storage resources are:
     1: File
     2: DDS-3-01
     3: DDS-3-02
     4: DDS-3-03
     5: Jaz
Select Storage resource (1-5): 3
Enter new Volume name: t08
Defined Pools:
     1: File
     2: DDS-3-01
     3: Jaz
     4: DDS-3-02
     5: DDS-3-03
Select the Pool (1-5): 4
Connecting to Storage daemon DDS-3-02 at bck01:9103 ...
Sending label command for Volume "t08" Slot 0 ...
3920 Cannot label Volume because it is already labeled: "t08"
Label command failed for Volume t08.
Do not forget to mount the drive!!!

Obviously the tape can not be labeled because it is already labeled. So I tried the relabel command:

*relabel
The defined Storage resources are:
     1: File
     2: DDS-3-01
     3: DDS-3-02
     4: DDS-3-03
     5: Jaz
Select Storage resource (1-5): 3
Defined Pools:
     1: File
     2: DDS-3-01
     3: Jaz
     4: DDS-3-02
     5: DDS-3-03
Select the Pool (1-5): 4
No results to list.
Enter *MediaId or Volume name: t08
sql_get.c:1062 Media record for Volume "t08" not found.

Relabeling the tape does not work because the media was not found in the database (I have also reinstalled the database). Labeling or relabeling within bacula does not work, so I have to use mt now. But first unmount the media:

*unmount
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
     1: File
     2: DDS-3-01
     3: DDS-3-02
     4: DDS-3-03
     5: Jaz
Select Storage resource (1-5): 3
3002 Device "DDS-3-02" (/dev/rmt/1l) unmounted.

Then connect as root user on the media server and use the mt command to delete the label on the tape:

# mt -f /dev/rmt/1l rewind
# mt -f /dev/rmt/1l weof 
# mt -f /dev/rmt/1l rewind

The -f option will specify the device file for the tape drive. The weof without any count will delete the mark for the numbers of records on the tape. If you have three tar files stored on a tape then then the EOF mark is set to 2. You can forward the tape to the last record with the following command:

# mt -f /dev/rmt/1l fsf 2

The weof command should work for reusing the the tapes. Go back to your bacula console and try to label the tape again:

*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
     1: File
     2: DDS-3-01
     3: DDS-3-02
     4: DDS-3-03
     5: Jaz
Select Storage resource (1-5): 3
Enter new Volume name: t08
Defined Pools:
     1: File
     2: DDS-3-01
     3: Jaz
     4: DDS-3-02
     5: DDS-3-03
Select the Pool (1-5): 4
Connecting to Storage daemon DDS-3-02 at bck01:9103 ...
Sending label command for Volume "t08" Slot 0 ...
3000 OK label. VolBytes=64512 DVD=0 Volume="t08" Device="DDS-3-02" (/dev/rmt/1l)
Catalog record for Volume "t08", Slot 0  successfully created.
Requesting to mount DDS-3-02 ...
3001 Mounted Volume: t08
3001 Device "DDS-3-02" (/dev/rmt/1l) is mounted with Volume "t08"

Finally I can reuse all my old tapes again.