%%
%%

\section*{Une br\`eve documentation}
\label{_ChapterStart1}
\index[general]{Une br\`eve documentation}
\index[general]{Documentation!br\`eve }
\addcontentsline{toc}{section}{Une br\`eve documentation}

Ce chapitre vous guidera \`a travers les \'etapes n\'ecessaires pour ex\'ecuter Bacula. 
Pour cela, nous supposons que vous avez install\'e Bacula, peut \^etre dans un simple 
r\'epertoire comme le d\'ecrit le chapitre pr\'ec\'edent, auquel cas vous pouvez ex\'ecuter 
Bacula sans \^etre root pour ces tests. Nous supposons d'autre part que vous n'avez 
pas modifi\'e les fichiers de configuration. Dans le cas contraire, nous vous 
recommandons de d\'esinstaller Bacula et de le r\'einstaller sans rien modifier. Les 
exemples de ce chapitre utilisent les fichiers de configuration par d\'efaut, et 
cr\'eent les volumes dans le r\'epertoire {\bf /tmp} de votre disque. De plus, les 
donn\'ees sauvegard\'ees seront celle du r\'epertoire des sources de Bacula o\`u vous 
l'avez compil\'e. Par cons\'equent, tous les {\it daemons} peuvent \^etre ex\'ecut\'es 
sans les droits root pour ces tests. Notez bien qu'en production, vos File 
Daemons devront \^etre ex\'ecut\'es en tant que root. Voyez le chapitre sur la 
s\'ecurit\'e pour plus d'informations sur ce sujet.

Voici les \'etapes que nous suivrons :

\begin{enumerate}
\item cd \lt{}install-directory\gt{}  
\item D\'emarrer la base de donn\'ees (si vous utilisez MySQL ou PostgreSQL)  
\item D\'emarrer les {\it daemons} avec {\bf ./bacula start}  
\item Lancer le programme Console pour interagir avec le Director 
\item Lancer un job
\item Lorsqu'un volume est plein, le d\'emonter, s'il s'agit d'une cartouche, en 
   \'etiqueter une nouvelle et poursuivre. Dans ce chapitre, nous n'\'ecrirons que sur 
   des volumes fichier, aussi vous n'avez pas \`a vous inqui\'eter au sujet des 
   cartouches pour le moment.
\item Tester la restauration de quelques fichiers depuis le volume fraichement \'ecrit 
   pour s'assurer de la validit\'e de la sauvegarde et qu'il est possible de restaurer. 
   Mieux vaut essayer avant qu'un d\'esastre ne survienne...   
\item Ajouter un second client.
   \end{enumerate}

Chacune de ces \'etapes est d\'ecrite en d\'etail ci-dessous.

\subsection*{Avant d'ex\'ecuter Bacula}
\index[general]{Bacula!Avant d'ex\'ecuter}
\index[general]{Avant d'ex\'ecuter Bacula}
\addcontentsline{toc}{subsection}{Avant d'ex\'ecuter Bacula}

Avant d'utiliser Bacula pour la premi\`ere fois en production, nous vous recommandons 
d'ex\'ecuter la commande {\test} du programme {\btape} ainsi qu'il est d\'ecrit 
dans le chapitre \ilink{Programmes utilitaires}{btape} de ce manuel. 
Ce programme vous aidera \`a vous assurer que votre lecteur de bandes fonctionne 
correctement avec Bacula. Si vous avez un lecteur moderne de marque HP, Sony, ou 
Quantum DDS ou DLT qui fonctionne sous Linux ou Solaris, vous pouvez probablement 
vous dispenser de faire ce test car Bacula est bien test\'e avec ces lecteurs et ces 
syst\`emes. Dans tous les autres cas, vous \^etes {\bf fortement} encourag\'e \`a 
ex\'ecuter les tests avant de poursuivre. {\bf btape} dispose aussi d'une commande 
{\bf fill} qui tente de reproduire le comportement de Bacula lorsqu'il remplit 
une cartouche et qu'il poursuit son \'ecriture sur la suivante. Vous devriez 
songer \`a faire ce test, sachez cependant qu'il peut \^etre long (environ 
4 heures sur mon lecteur) de remplir une cartouche de haute capacit\'e. 

\subsection*{D\'emarrer la base de donn\'ees}
\label{StartDB}
\index[general]{D\'emarrer la base de donn\'ees}
\index[general]{base de donn\'ees!D\'emarrer la }
\addcontentsline{toc}{subsection}{D\'emarrer la base de donn\'ees}

Si vous utilisez MySQL ou PostgreSQL pour votre catalogue Bacula, vous devez 
d\'emarrer la base de donn\'ees avant d'essayer de lancer un job pour \'eviter 
d'obtenir des messages d'erreur au d\'emarrage de Bacula. J'utilise les scripts 
{\bf startmysql} et {\bf stopmysql} pour d\'emarrer mon MySQL local. Notez que si 
vous utilisez SQLite, vous n'aurez pas \`a utiliser  {\bf startmysql} ou {\bf stopmysql}. 
Si vous utilisez ceci en production, vous souhaiterez probablement trouver 
un moyen pour d\'emarrer automatiquement MySQL ou PostgreSQL apr\`es chaque 
red\'emarrage du syst\`eme.

Si vous utilisez SQLite (c'est \`a dire, si vous avez sp\'ecifi\'e l'option 
{\bf \verb:--:with-sqlite=xxx} de la commande {\bf ./configure}, vous n'avez rien \`a faire. 
SQLite est d\'emarr\'ee automatiquement par {\bf Bacula}.

\subsection*{D\'emarrer les daemons}
\label{StartDaemon}
\index[general]{D\'emarrer les daemons}
\index[general]{Daemons!D\'emarrer les}
\addcontentsline{toc}{subsection}{D\'emarrer les daemons}

Que vous ayez compil\'e Bacula depuis les sources ou que vous ayez install\'e les rpms, 
tapez simplement :

./bacula start

dans votre r\'epertoire d'installation pour d\'emarrer les trois {\it daemons}.

Le script {\bf bacula} lance le Storage Daemon, le File Daemon et le Director Daemon, qui 
tournent tous trois en tant que {\it daemons} en t\^ache de fond. Si vous utilisez 
la fonction de d\'emarrage automatique de Bacula, vous pouvez, au choix, lancer les 
trois {\it daemons} lors du d\'emarrage, ou au contraire les lancer individuellement 
avec les scripts  {\bf bacula-dir}, {\bf bacula-fd}, et {\bf bacula-sd} usuellement 
situ\'es dans {\bf /etc/init.d}, bien que leur localisation effective soit d\'ependante du syst\`eme 
d'exploitation.

Notez que seul le File Daemon a \'et\'e port\'e sur les syst\`emes Windows, et qu'il doit \^etre 
d\'emarr\'e diff\'eramment. Veuillez consulter le chapitre  
\ilink{La version Windows de Bacula}{_ChapterStart7} de ce manuel.

Les paquetages rpm configurent les {\it daemons} pour qu'ils s'ex\'ecutent en tant 
qu'utilisateur root et en tant que groupe bacula. Le processus d'installation rpm 
se charge de cr\'eer le groupe bacula s'il n'existe pas sur le syst\`eme. Tout utilisateur 
ajout\'e au groupe bacula h\'erite de l'acc\`es aux fichiers cr\'e\'es par les {\it daemons}. Pour 
modifier ce comportement, \'editez les scripts de d\'emarrage des {\it daemons} :

\begin{itemize}
  \item /etc/bacula/bacula 
  \item /etc/init.d/bacula-dir 
  \item /etc/init.d/bacula-sd 
  \item /etc/init.d/bacula-fd 
\end{itemize}

puis red\'emarrez-les.

Le chapitre 
\ilink{installation}{_ChapterStart17} de ce manuel indique comment installer 
les scripts de d\'emarrage automatique des {\it daemons}.

\subsection*{Interagir avec le Director pour l'interroger sur l'\'etat de Bacula ou lancer des jobs}
\index[general]{Jobs!Interagir avec le Director pour interroger l'\'etat de Bacula ou lancer des}
\index[general]{Interagir avec le Director pour interroger l'\'etat de Bacula ou lancer des jobs}
\addcontentsline{toc}{subsection}{Interagir avec le Director pour interroger l'\'etat de Bacula ou lancer des jobs}

Pour communiquer avec le Director et pour s'enqu\'erir de l'\'etat de Bacula ou de jobs en 
cours d'ex\'ecution, tapez simplement :

./bconsole

dans le r\'epertoire de plus haut niveau.

Si vous avez install\'e la console GNOME et utilis\'e l'option {\bf \verb:--:enable-gnome} 
de la commande configure, vous pouvez aussi utiliser la console GNOME en tapant : 

./gnome-console

Vous pouvez aussi utiliser le programme wxWidgets {\bf wx-console}.

Pour simplifier, nous ne d\'ecrirons ici que le programme {\bf ./bconsole}. La plus 
grande partie de ce qui est d\'ecrit ici s'applique aussi aux programmes {\bf ./gnome-console} 
et {\bf wx-console}.

La commande {\bf ./bconsole} lance le programme Console, qui se connecte au Director. 
Bacula \'etant un programme r\'eseau, vous pouvez utiliser la Console depuis n'importe quelle 
machine de votre r\'eseau. Cependant, la plupart du temps le Console est ex\'ecut\'ee sur la 
m\^eme machine que le Director. En principe, la Console devrait produire un affichage 
similaire \`a :  

\footnotesize
\begin{verbatim}
[kern@polymatou bin]$ ./bconsole
Connecting to Director lpmatou:9101
1000 OK: HeadMan Version: 1.30 (28 April 2003)
*
\end{verbatim}
\normalsize

L'ast\'erisque est l'invite de commande de la console.

Tapez {\bf help} pour obtenir la liste des commandes disponibles :

\footnotesize
\begin{verbatim}
*help
  Command    Description
  =======    ===========
  add        add media to a pool
  autodisplay autodisplay [on/off] -- console messages
  automount  automount [on/off] -- after label
  cancel     cancel job=nnn -- cancel a job
  create     create DB Pool from resource
  delete     delete [pool=<pool-name> | media volume=<volume-name>]
  estimate   performs FileSet estimate debug=1 give full listing
  exit       exit = quit
  help       print this command
  label      label a tape
  list       list [pools | jobs | jobtotals | media <pool> |
             files jobid=<nn>]; from catalog
  llist      full or long list like list command
  messages   messages
  mount      mount <storage-name>
  prune      prune expired records from catalog
  purge      purge records from catalog
  query      query catalog
  quit       quit
  relabel    relabel a tape
  release    release <storage-name>
  restore    restore files
  run        run <job-name>
  setdebug   sets debug level
  show       show (resource records) [jobs | pools | ... | all]
  sqlquery   use SQL to query catalog
  status     status [storage | client]=<name>
  time       print current time
  unmount    unmount <storage-name>
  update     update Volume or Pool
  use        use catalog xxx
  var        does variable expansion
  version    print Director version
  wait       wait until no jobs are running
*
\end{verbatim}
\normalsize

Pour plus de d\'etails sur les commandes de la console, consultez le chapitre 
\ilink{Console}{_ConsoleChapter} de ce manuel. 

\subsection*{ex\'ecuter un job}
\label{Running}
\index[general]{Job!ex\'ecuter un}
\index[general]{ex\'ecuter un job}
\addcontentsline{toc}{subsection}{Ex\'ecuter un job}

A ce stade, nous supposons que vous avez :

\begin{itemize}
\item Configur\'e Bacula avec la commande {\bf ./configure \verb:--:your-options} 
\item Compil\'e Bacula avec la commande {\bf make} 
\item Install\'e Bacula avec la commande {\bf make install} 
\item Cr\'e\'e votre catalogue avec, par exemple, la commande {\bf
   ./create\_sqlite\_database} 
\item Cr\'e\'e les tables du catalogue avec la commande {\bf
   ./make\_bacula\_tables} 
\item Eventuellement \'edit\'e votre fichier  {\bf bacula-dir.conf} pour le personnaliser 
   quelque peu. ATTENTION ! Si vous modifiez le nom du Director ou son mot de passe, 
   vous devez faire les modifications correspondantes dans les autres fichiers de 
   configuration. Il est sans dout pr\'ef\'erable, pour l'instant, de ne rien changer.
\item D\'emarr\'e Bacula avec la commande {\bf ./bacula start}
\item Invoqu\'e le programme Console avec la commande {\bf ./bconsole}.
\end{itemize}

En outre, nous supposons pour le moment que vous utilisez les fichiers de configuration 
par d\'efaut.

Maintenant, entrez les commandes suivantes :

\footnotesize
\begin{verbatim}
show filesets
\end{verbatim}
\normalsize

Vous devriez obtenir quelque chose comme :

\footnotesize
\begin{verbatim}
FileSet: name=Full Set
      O M
      N
      I /home/kern/bacula/regress/build
      N
      E /proc
      E /tmp
      E /.journal
      E /.fsck
      N
FileSet: name=Catalog
      O M
      N
      I /home/kern/bacula/regress/working/bacula.sql
      N
\end{verbatim}
\normalsize

Il s'agit d'un {\bf FileSet} pr\'ed\'efini qui sauvegardera le r\'epertoire des 
sources de Bacula. Les noms de r\'epertoires qui seront r\'eellement affich\'es 
devraient correspondre \`a votre configuration. Dans une perspective de tests, 
nous avons choisi un r\'epertoire de taille et de complexit\'e mod\'er\'ee (environ 
40 Mo). Le FileSet {\bf Catalog} est utilis\'e pour sauvegarder le catalogue 
Bacula et nous ne nous y attarderons pas pour le moment. Les entr\'ees {\bf I} 
sont les fichiers ou r\'epertoires qui seront inclus dans la sauvegarde, tandis 
que les entr\'ees  {\bf E} sont ceux qui en seront exclus, quand aux entr\'ees {\bf O}, 
ce sont les options sp\'ecifi\'ees pour ce FileSet. Vous pouvez changer ce qui est 
sauvegard\'e en modifiant la ligne {\bf File =} de la ressource {\bf FileSet}.


Il est maintenant temps de lancer votre premi\`ere sauvegarde. Nous allons 
sauvegarder votre r\'epertoire sources de Bacula vers un volume File dans votre 
r\'epertoire {\bf /tmp} afin de vous montrer combien c'est facile. Saisissez :  

\footnotesize
\begin{verbatim}
status dir
\end{verbatim}
\normalsize

Vous devriez obtenir :

\footnotesize
\begin{verbatim}
rufus-dir Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Console connected at 28-Apr-2003 14:03
No jobs are running.
Level          Type     Scheduled          Name
=================================================================
Incremental    Backup   29-Apr-2003 01:05  Client1
Full           Backup   29-Apr-2003 01:10  BackupCatalog
====
\end{verbatim}
\normalsize

O\`u les dates et le nom du Director seront diff\'erents et en accord avec votre 
installation. Ceci montre qu'une sauvegarde incr\'ementale est planifi\'ee pour 
le job {\bf Client1} \`a 1h05, et qu'une sauvegarde full est planifi\'ee pour 
le job {\bf BackupCatalog} \`a 1h10. Vous devriez remplacer le nom {\bf Client1} 
par celui de votre machine, sinon vous risquez la confusion lorsque vous 
ajouterez de nouveaux clients. Pour ma machine r\'eelle, j'utilise {\bf Rufus} 
plut\^ot que {\bf Client1}.

A pr\'esent, tapez :

\footnotesize
\begin{verbatim}
status client
\end{verbatim}
\normalsize

Vous devriez obtenir :

\footnotesize
\begin{verbatim}
The defined Client resources are:
     1: rufus-fd
Item 1 selected automatically.
Connecting to Client rufus-fd at rufus:8102
rufus-fd Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Director connected at: 28-Apr-2003 14:14
No jobs running.
====
\end{verbatim}
\normalsize

Dans ce cas, le client se nomme {\bf rufus-fd}, votre nom sera diff\'erent, mais la 
ligne qui d\'ebute par {\bf rufus-fd Version...} est produite par votre File Daemon, 
nous sommes donc maintenant surs qu'il fonctionne.

Finalement, faites de m\^eme pour votre Storage Daemon :

\footnotesize
\begin{verbatim}
status storage
\end{verbatim}
\normalsize

Vous devriez obtenir :

\footnotesize
\begin{verbatim}
The defined Storage resources are:
     1: File
Item 1 selected automatically.
Connecting to Storage daemon File at rufus:8103
rufus-sd Version: 1.30 (28 April 2003)
Daemon started 28-Apr-2003 14:03, 0 Jobs run.
Device /tmp is not open.
No jobs running.
====
\end{verbatim}
\normalsize

Vous noterez que le p\'eriph\'erique du Storage Daemon par d\'efaut est nomm\'e {\bf File} 
et qu'il utilise le p\'eriph\'erique {\bf /tmp}, qui n'est actuellement pas ouvert. 

Maintenant, lancez un job :

\footnotesize
\begin{verbatim}
run
\end{verbatim}
\normalsize
 
Vous devriez obtenir :

\footnotesize
\begin{verbatim}
Using default Catalog name=MyCatalog DB=bacula
A job name must be specified.
The defined Job resources are:
     1: Client1
     2: BackupCatalog
     3: RestoreFiles
Select Job resource (1-3):
\end{verbatim}
\normalsize

Ici, Bacula affiche la liste des trois diff\'erents jobs que vous pouvez ex\'ecuter. 
Choisissez le num\'ero {\bf 1} et validez (entr\'ee).

Vous devriez obtenir :

\footnotesize
\begin{verbatim}
Run Backup job
JobName:  Client1
FileSet:  Full Set
Level:    Incremental
Client:   rufus-fd
Storage:  File
Pool:     Default
When:     2003-04-28 14:18:57
OK to run? (yes/mod/no):
\end{verbatim}
\normalsize

Prenez un peu de temps pour examiner cet affichage et le comprendre. Il vous 
est demand\'e de valider, modifier ou annuler l'ex\'ecution d'un job nomm\'e 
{\bf Client1} avec le FileSet {\bf Full Set} que nous avons affich\'e plus haut 
en incr\'emental sur votre client rufus, utilisant le p\'eriph\'erique de stockage 
{\bf File} et le pool {\bf Default} \`a la date indiqu\'ee sur la ligne "When".

Nous avons le choix de valider ({\bf yes}), modifier un ou plusieurs des 
param\`etres ci-dessus ({\bf mod}), ou de ne pas ex\'ecuter le job ({\bf no}). 

Validez l'ex\'ecution du job ({\bf yes}), vous devriez imm\'ediatement obtenir 
l'invite de commande de la console (un ast\'erisque). Apr\`es quelques minutes, 
la commande {\bf messages} devrait produire un r\'esultat tel que :

\footnotesize
\begin{verbatim}
28-Apr-2003 14:22 rufus-dir: Last FULL backup time not found. Doing
                  FULL backup.
28-Apr-2003 14:22 rufus-dir: Start Backup JobId 1,
                  Job=Client1.2003-04-28_14.22.33
28-Apr-2003 14:22 rufus-sd: Job Client1.2003-04-28_14.22.33 waiting.
                  Cannot find any appendable volumes.
Please use the "label"  command to create a new Volume for:
    Storage:      FileStorage
    Media type:   File
    Pool:         Default
\end{verbatim}
\normalsize

Le premier message signale qu'aucune sauvegarde full n'a jamais \'et\'e faite, et 
que par cons\'equent Bacula \'el\`eve votre incr\'ementale en une Full (ce comportement 
est normal). Le second message indique que le job a d\'emarr\'e avec le JobId 1 et le 
troisi\`eme message vous informe que Bacula ne peut trouver aucun volume dans le 
pool Default sur lequel \'ecrire les donn\'ees du job. Ceci est normal, car nous 
n'avons encore cr\'e\'e (ou \'etiquet\'e) aucun volume. Bacula vous fournit tous les d\'etails 
concernant le volume dont il a besoin. 

A ce point, le job est bloqu\'e en attente d'un volume. Vous pouvez le v\'erifier 
en utilisant la commande {\bf status dir}. Pour continuer, vous devez cr\'eer un 
volume sur lequel Bacula pourra \'ecrire. Voici la manipulation :

\footnotesize
\begin{verbatim}
label
\end{verbatim}
\normalsize

Bacula devrait afficher :

\footnotesize
\begin{verbatim}
The defined Storage resources are:
     1: File
Item 1 selected automatically.
Enter new Volume name:
\end{verbatim}
\normalsize

Entrez un nom commençant par une lettre et ne contenant que des chiffres et des lettres 
(p\'eriodes, tirets et soulign\'e "_" sont aussi autoris\'es). Par exemple entrez {\bf TestVolume001}, 
vous devriez obtenir : 

\footnotesize
\begin{verbatim}
Defined Pools:
     1: Default
Item 1 selected automatically.
Connecting to Storage daemon File at rufus:8103 ...
Sending label command for Volume "TestVolume001" Slot 0 ...
3000 OK label. Volume=TestVolume001 Device=/tmp
Catalog record for Volume "TestVolume002", Slot 0  successfully created.
Requesting mount FileStorage ...
3001 OK mount. Device=/tmp
\end{verbatim}
\normalsize

Finalement, tapez la commande {\bf messages}, vous devriez obtenir quelque chose comme :

\footnotesize
\begin{verbatim}
28-Apr-2003 14:30 rufus-sd: Wrote label to prelabeled Volume
   "TestVolume001" on device /tmp
28-Apr-2003 14:30 rufus-dir: Bacula 1.30 (28Apr03): 28-Apr-2003 14:30
JobId:                  1
Job:                    Client1.2003-04-28_14.22.33
FileSet:                Full Set
Backup Level:           Full
Client:                 rufus-fd
Start time:             28-Apr-2003 14:22
End time:               28-Apr-2003 14:30
Files Written:          1,444
Bytes Written:          38,988,877
Rate:                   81.2 KB/s
Software Compression:   None
Volume names(s):        TestVolume001
Volume Session Id:      1
Volume Session Time:    1051531381
Last Volume Bytes:      39,072,359
FD termination status:  OK
SD termination status:  OK
Termination:            Backup OK
28-Apr-2003 14:30 rufus-dir: Begin pruning Jobs.
28-Apr-2003 14:30 rufus-dir: No Jobs found to prune.
28-Apr-2003 14:30 rufus-dir: Begin pruning Files.
28-Apr-2003 14:30 rufus-dir: No Files found to prune.
28-Apr-2003 14:30 rufus-dir: End auto prune.
\end{verbatim}
\normalsize

Si rien ne se passe dans l'imm\'ediat, vous pouvez continuer de rentrer la 
commande {\bf messages} jusqu'\`a ce que le job se termine, ou utiliser la 
commande {\bf autodisplay on} afin que les messages soient affich\'es d\`es-qu'ils 
sont disponibles.

si vous faites {\bf ls -l} dans votre r\'epertoire {\bf /tmp}, vous verrez 
l'\'el\'ement suivant : 

\footnotesize
\begin{verbatim}
-rw-r-----    1 kern     kern     39072153 Apr 28 14:30 TestVolume001
\end{verbatim}
\normalsize

Il s'agit du volume File que vous venez juste d'\'ecrire, et qui contient toutes 
les donn\'ees du job que vous venez d'ex\'ecuter. Si vous ex\'ecutez d'autres jobs, 
il seront ajout\'es \`a la suite de ce volume, \`a moins que vous n'ayez sp\'ecifi\'e 
un autre comportement.

Vous vous demandez peut-\^etre s'il va vous falloir \'etiqueter vous même chaque 
volume que Bacula sera amen\'e \`a utiliser. La r\'eponse, en ce qui concerne les 
volumes disque tels que celui que nous avons utilis\'e, est non. Il est possible 
de param\'etrer Bacula pour qu'il cr\'e\'ee lui même les volumes. En revanche, 
pour les volumes de type cartouche, il vous faudra tr\`es probablement 
\'etiqueter chaque volume que vous voulez utiliser.

Si vous souhaitez en rester l\`a, saisissez simplement {\bf quit} dans la 
console, puis stoppez Bacula avec {\bf ./bacula stop}. Pour nettoyer 
votre installation des r\'esultats de vos tests, supprimez le fichier 
 {\bf /tmp/TestVolume001}, et r\'einitialiser votre catalogue en utilisant :

\footnotesize
\begin{verbatim}
./drop_bacula_tables
./make_bacula_tables
\end{verbatim}
\normalsize

Notez bien que ceci supprimera toutes les informations concernant les jobs pr\'ec\'edemment 
ex\'ecut\'es et que, si c'est sans doute ce que vous souhaitez faire en fin de phase de 
test, ce n'est g\'en\'eralement pas une op\'eration souhaitable en utilisation normale.

Si vous souhaitez essayer de restaurer les fichiers que vous venez de sauvegarder, 
lisez la section suivante.

\label{restoring}

\subsection*{Restoring Your Files}
\index[general]{Files!Restoring Your }
\index[general]{Restoring Your Files }
\addcontentsline{toc}{subsection}{Restoring Your Files}

If you have run the default configuration and the save of the Bacula source
code as demonstrated above, you can restore the backed up files in the Console
program by entering: 

\footnotesize
\begin{verbatim}
restore all
\end{verbatim}
\normalsize

where you will get: 

\footnotesize
\begin{verbatim}
First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.

To select the JobIds, you have the following choices:
     1: List last 20 Jobs run
     2: List Jobs where a given File is saved
     3: Enter list of comma separated JobIds to select
     4: Enter SQL list command
     5: Select the most recent backup for a client
     6: Select backup for a client before a specified time
     7: Enter a list of files to restore
     8: Enter a list of files to restore before a specified time
     9: Find the JobIds of the most recent backup for a client
    10: Find the JobIds for a backup for a client before a specified time
    11: Enter a list of directories to restore for found JobIds
    12: Cancel
Select item:  (1-12): 
\end{verbatim}
\normalsize

As you can see, there are a number of options, but for the current
demonstration, please enter {\bf 5} to do a restore of the last backup you
did, and you will get the following output: 

\footnotesize
\begin{verbatim}
Defined Clients:
     1: rufus-fd
Item 1 selected automatically.
The defined FileSet resources are:
     1: 1  Full Set  2003-04-28 14:22:33
Item 1 selected automatically.
+-------+-------+----------+---------------------+---------------+
| JobId | Level | JobFiles | StartTime           | VolumeName    |
+-------+-------+----------+---------------------+---------------+
| 1     | F     | 1444     | 2003-04-28 14:22:33 | TestVolume002 |
+-------+-------+----------+---------------------+---------------+
You have selected the following JobId: 1
Building directory tree for JobId 1 ...
1 Job inserted into the tree and marked for extraction.
The defined Storage resources are:
     1: File
Item 1 selected automatically.
You are now entering file selection mode where you add and
remove files to be restored. All files are initially added.
Enter "done" to leave this mode.
cwd is: /
$
\end{verbatim}
\normalsize

where I have truncated the listing on the right side to make it more readable.
As you can see by starting at the top of the listing, Bacula knows what client
you have, and since there was only one, it selected it automatically, likewise
for the FileSet. Then Bacula produced a listing containing all the jobs that
form the current backup, in this case, there is only one, and the Storage
daemon was also automatically chosen. Bacula then took all the files that were
in Job number 1 and entered them into a {\bf directory tree} (a sort of in
memory representation of your filesystem). At this point, you can use the {\bf
cd} and {\bf ls} ro {\bf dir} commands to walk up and down the directory tree
and view what files will be restored. For example, if I enter {\bf cd
/home/kern/bacula/bacula-1.30} and then enter {\bf dir} I will get a listing
of all the files in the Bacula source directory. On your system, the path will
be somewhat different. For more information on this, please refer to the 
\ilink{Restore Command Chapter}{_ChapterStart13} of this manual for
more details. 

To exit this mode, simply enter: 

\footnotesize
\begin{verbatim}
done
\end{verbatim}
\normalsize

and you will get the following output: 

\footnotesize
\begin{verbatim}
Bootstrap records written to
   /home/kern/bacula/testbin/working/restore.bsr
The restore job will require the following Volumes:
   
   TestVolume001
1444 files selected to restore.
Run Restore job
JobName:    RestoreFiles
Bootstrap:  /home/kern/bacula/testbin/working/restore.bsr
Where:      /tmp/bacula-restores
Replace:    always
FileSet:    Full Set
Client:     rufus-fd
Storage:    File
JobId:      *None*
When:       2005-04-28 14:53:54
OK to run? (yes/mod/no):
\end{verbatim}
\normalsize

If you answer {\bf yes} your files will be restored to {\bf
/tmp/bacula-restores}. If you want to restore the files to their original
locations, you must use the {\bf mod} option and explicitly set {\bf Where:}
to nothing (or to /). We recommend you go ahead and answer {\bf yes} and after
a brief moment, enter {\bf messages}, at which point you should get a listing
of all the files that were restored as well as a summary of the job that looks
similar to this: 

\footnotesize
\begin{verbatim}
28-Apr-2005 14:56 rufus-dir: Bacula 1.30 (28Apr03): 28-Apr-2003 14:56
JobId:                  2
Job:                    RestoreFiles.2005-04-28_14.56.06
Client:                 rufus-fd
Start time:             28-Apr-2005 14:56
End time:               28-Apr-2005 14:56
Files Restored:         1,444
Bytes Restored:         38,816,381
Rate:                   9704.1 KB/s
FD termination status:  OK
Termination:            Restore OK
28-Apr-2005 14:56 rufus-dir: Begin pruning Jobs.
28-Apr-2005 14:56 rufus-dir: No Jobs found to prune.
28-Apr-2005 14:56 rufus-dir: Begin pruning Files.
28-Apr-2005 14:56 rufus-dir: No Files found to prune.
28-Apr-2005 14:56 rufus-dir: End auto prune.
\end{verbatim}
\normalsize

After exiting the Console program, you can examine the files in {\bf
/tmp/bacula-restores}, which will contain a small directory tree with all the
files. Be sure to clean up at the end with: 

\footnotesize
\begin{verbatim}
rm -rf /tmp/bacula-restore
\end{verbatim}
\normalsize

\subsection*{Quitting the Console Program}
\index[general]{Program!Quitting the Console }
\index[general]{Quitting the Console Program }
\addcontentsline{toc}{subsection}{Quitting the Console Program}

Simply enter the command {\bf quit}. 
\label{SecondClient}

\subsection*{Adding a Second Client}
\index[general]{Client!Adding a Second }
\index[general]{Adding a Second Client }
\addcontentsline{toc}{subsection}{Adding a Second Client}

If you have gotten the example shown above to work on your system, you may be
ready to add a second Client (File daemon). That is you have a second machine
that you would like backed up. The only part you need installed on the other
machine is the binary {\bf bacula-fd} (or {\bf bacula-fd.exe} for Windows) and
its configuration file {\bf bacula-fd.conf}. You can start with the same {\bf
bacula-fd.conf} file that you are currently using and make one minor
modification to it to create the conf file for your second client. Change the
File daemon name from whatever was configured, {\bf rufus-fd} in the example
above, but your system will have a different name. The best is to change it to
the name of your second machine. For example: 

\footnotesize
\begin{verbatim}
...
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = rufus-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /home/kern/bacula/working
  Pid Directory = /var/run
}
...
\end{verbatim}
\normalsize

would become: 

\footnotesize
\begin{verbatim}
...
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = matou-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /home/kern/bacula/working
  Pid Directory = /var/run
}
...
\end{verbatim}
\normalsize

where I show just a portion of the file and have changed {\bf rufus-fd} to
{\bf matou-fd}. The names you use are your choice. For the moment, I recommend
you change nothing else. Later, you will want to change the password. 

Now you should install that change on your second machine. Then you need to
make some additions to your Director's configuration file to define the new
File daemon or Client. Starting from our original example which should be
installed on your system, you should add the following lines (essentially
copies of the existing data but with the names changed) to your Director's
configuration file {\bf bacula-dir.conf}. 

\footnotesize
\begin{verbatim}
#
# Define the main nightly save backup job
#   By default, this job will back up to disk in /tmp
Job {
  Name = "Matou"
  Type = Backup
  Client = matou-fd
  FileSet = "Full Set"
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = Default
  Write Bootstrap = "/home/kern/bacula/working/matou.bsr"
}
# Client (File Services) to backup
Client {
  Name = matou-fd
  Address = matou
  FDPort = 9102
  Catalog = MyCatalog
  Password = "xxxxx"                  # password for
  File Retention = 30d                # 30 days
  Job Retention = 180d                # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}
\end{verbatim}
\normalsize

Then make sure that the Address parameter in the Storage resource is set to
the fully qualified domain name and not to something like "localhost". The
address specified is sent to the File daemon (client) and it must be a fully
qualified domain name. If you pass something like "localhost" it will not
resolve correctly and will result in a time out when the File daemon fails to
connect to the Storage daemon. 

That is all that is necessary. I copied the existing resource to create a
second Job (Matou) to backup the second client (matou-fd). It has the name
{\bf Matou}, the Client is named {\bf matou-fd}, and the bootstrap file name
is changed, but everything else is the same. This means that Matou will be
backed up on the same schedule using the same set of tapes. You may want to
change that later, but for now, let's keep it simple. 

The second change was to add a new Client resource that defines {\bf matou-fd}
and has the correct address {\bf matou}, but in real life, you may need a
fully qualified domain name or an IP address. I also kept the password the
same (shown as xxxxx for the example). 

At this point, if you stop Bacula and restart it, and start the Client on the
other machine, everything will be ready, and the prompts that you saw above
will now include the second machine. 

To make this a real production installation, you will possibly want to use
different Pool, or a different schedule. It is up to you to customize. In any
case, you should change the password in both the Director's file and the
Client's file for additional security. 

For some important tips on changing names and passwords, and a diagram of what
names and passwords must match, please see 
\ilink{Authorization Errors}{AuthorizationErrors} in the FAQ chapter
of this manual. 

\subsection*{When The Tape Fills}
\label{FullTape}
\index[general]{Fills!When The Tape }
\index[general]{When The Tape Fills }
\addcontentsline{toc}{subsection}{When The Tape Fills}

If you have scheduled your job, typically nightly, there will come a time when
the tape fills up and {\bf Bacula} cannot continue. In this case, Bacula will
send you a message similar to the following: 

\footnotesize
\begin{verbatim}
rufus-sd: block.c:337 === Write error errno=28: ERR=No space left
          on device
\end{verbatim}
\normalsize

This indicates that Bacula got a write error because the tape is full. Bacula
will then search the Pool specified for your Job looking for an appendable
volume. In the best of all cases, you will have properly set your Retention
Periods and you will have all your tapes marked to be Recycled, and {\bf
Bacula} will automatically recycle the tapes in your pool requesting and
overwriting old Volumes. For more information on recycling, please see the 
\ilink{Recycling chapter}{_ChapterStart22} of this manual. If you
find that your Volumes were not properly recycled (usually because of a
configuration error), please see the 
\ilink{Manually Recycling Volumes}{manualrecycling} section of
the Recycling chapter. 

If like me, you have a very large set of Volumes and you label them with the
date the Volume was first writing, or you have not set up your Retention
periods, Bacula will not find a tape in the pool, and it will send you a
message similar to the following: 

\footnotesize
\begin{verbatim}
rufus-sd: Job kernsave.2002-09-19.10:50:48 waiting. Cannot find any
          appendable volumes.
Please use the "label"  command to create a new Volume for:
    Storage:      SDT-10000
    Media type:   DDS-4
    Pool:         Default
\end{verbatim}
\normalsize

Until you create a new Volume, this message will be repeated an hour later,
then two hours later, and so on doubling the interval each time up to a
maximum interval of 1 day. 

The obvious question at this point is: What do I do now? 

The answer is simple: first, using the Console program, close the tape drive
using the {\bf unmount} command. If you only have a single drive, it will be
automatically selected, otherwise, make sure you release the one specified on
the message (in this case {\bf STD-10000}). 

Next, you remove the tape from the drive and insert a new blank tape. Note, on
some older tape drives, you may need to write an end of file mark ({\bf mt \
-f \ /dev/nst0 \ weof}) to prevent the drive from running away when Bacula
attempts to read the label. 

Finally, you use the {\bf label} command in the Console to write a label to
the new Volume. The {\bf label} command will contact the Storage daemon to
write the software label, if it is successful, it will add the new Volume to
the Pool, then issue a {\bf mount} command to the Storage daemon. See the
previous sections of this chapter for more details on labeling tapes. 

The result is that Bacula will continue the previous Job writing the backup to
the new Volume. 

If you have a Pool of volumes and Bacula is cycling through them, instead of
the above message "Cannot find any appendable volumes.", Bacula may ask you
to mount a specific volume. In that case, you should attempt to do just that.
If you do not have the volume any more (for any of a number of reasons), you
can simply mount another volume from the same Pool, providing it is
appendable, and Bacula will use it. You can use the {\bf list volumes} command
in the console program to determine which volumes are appendable and which are
not. 

If like me, you have your Volume retention periods set correctly, but you have
no more free Volumes, you can relabel and reuse a Volume as follows: 

\begin{itemize}
\item Do a {\bf list volumes} in the Console and select the oldest  Volume for
   relabeling.  
\item If you have setup your Retention periods correctly, the  Volume should
   have VolStatus {\bf Purged}.  
\item If the VolStatus is not set to Purged, you will need to purge  the
   database of Jobs that are written on that Volume. Do so  by using the command
   {\bf purge jobs volume} in the Console.  If you have multiple Pools, you will
be prompted for the  Pool then enter the VolumeName (or MediaId) when
requested.  
\item Then simply use the {\bf relabel} command to relabel the  Volume. 
   \end{itemize}

To manually relabel the Volume use the following additional steps: 

\begin{itemize}
\item To delete the Volume from the catalog use the {\bf delete volume} 
   command in the Console and select the VolumeName (or MediaId) to be  deleted. 

\item Use the {\bf unmount} command in the Console to unmount the  old tape.  
\item Physically relabel the old Volume that you deleted so that it  can be
   reused.  
\item Insert the old Volume in the tape drive.  
\item From a command line do: {\bf mt \ -f \ /dev/st0 \ rewind} and  {\bf mt \
   -f \ /dev/st0 \ weof}, where you need to use the proper  tape drive name for
   your system in place of {\bf /dev/st0}.  
\item Use the {\bf label} command in the Console to write a new  Bacula label
   on your tape.  
\item Use the {\bf mount} command in the Console if it is not automatically 
   done, so that Bacula starts using your newly labeled tape. 
   \end{itemize}

\subsection*{Other Useful Console Commands}
\index[general]{Commands!Other Useful Console }
\index[general]{Other Useful Console Commands }
\addcontentsline{toc}{subsection}{Other Useful Console Commands}

\begin{description}

\item [status dir]
   \index[console]{status dir }
   Print a status of all running jobs and jobs  scheduled in the next 24 hours.  

\item [status]
   \index[console]{status }
   The console program will prompt you to select  a daemon type, then will
request the daemon's status.  

\item [status jobid=nn]
   \index[console]{status jobid }
   Print a status of JobId nn if it is running.  The Storage daemon is contacted
and requested to print a current  status of the job as well.  

\item [list pools]
   \index[console]{list pools }
   List the pools defined in the Catalog (normally  only Default is used).  

\item [list media]
   \index[console]{list media }
   Lists all the media defined in the Catalog.  

\item [list jobs]
   \index[console]{list jobs }
   Lists all jobs in the Catalog that have run.  

\item [list jobid=nn]
   \index[console]{list jobid }
   Lists JobId nn from the Catalog.  

\item [list jobtotals]
   \index[console]{list jobtotals }
   Lists totals for all jobs in the Catalog.  

\item [list files jobid=nn]
   \index[console]{list files jobid }
   List the files that were saved for JobId nn.  

\item [list jobmedia]
   \index[console]{list jobmedia }
   List the media information for each Job run.  

\item [messages]
   \index[console]{messages }
   Prints any messages that have been directed to the console.  

\item [unmount storage=storage-name]
   \index[console]{unmount storage }
   Unmounts the drive associated with the storage  device with the name {\bf
storage-name} if the drive is not currently being  used. This command is used
if you wish Bacula to free the drive so  that you can use it to label a tape. 


\item [mount storage=storage-name]
   \index[sd]{mount storage }
   Causes the drive associated with the  storage device to be mounted again. When
Bacula reaches the end of a volume and requests you to mount a  new volume,
you must issue this command after you have placed the  new volume in the
drive. In effect, it is the signal needed by  Bacula to know to start reading
or writing the new volume.  

\item [quit]
   \index[sd]{quit }
   Exit or quit the console program. 
\end{description}

Most of the commands given above, with the exception of {\bf list}, will
prompt you for the necessary arguments if you simply enter the command name. 

\subsection*{Debug Daemon Output}
\index[general]{Debug Daemon Output }
\index[general]{Output!Debug Daemon }
\addcontentsline{toc}{subsection}{Debug Daemon Output}

If you want debug output from the daemons as they are running, start the
daemons from the install directory as follows: 

\footnotesize
\begin{verbatim}
./bacula start -d100
\end{verbatim}
\normalsize

This can be particularly helpful if your daemons do not start correctly,
because direct daemon output to the console is normally directed to the
NULL device, but with the debug level greater than zero, the output
will be sent to the starting terminal.

To stop the three daemons, enter the following from the install directory: 

\footnotesize
\begin{verbatim}
./bacula stop
\end{verbatim}
\normalsize

The execution of {\bf bacula stop} may complain about pids not found. This is
OK, especially if one of the daemons has died, which is very rare. 

To do a full system save, each File daemon must be running as root so that it
will have permission to access all the files. None of the other daemons
require root privileges. However, the Storage daemon must be able to open the
tape drives. On many systems, only root can access the tape drives. Either run
the Storage daemon as root, or change the permissions on the tape devices to
permit non-root access. MySQL and PostgreSQL can be installed and run with any
userid; root privilege is not necessary. 

\subsection*{Have Patience When Starting the Daemons or Mounting Blank Tapes}
\index[general]{Have Patience When Starting the Daemons or Mounting Blank
Tapes }
\index[general]{Tapes!Have Patience When Starting the Daemons or Mounting
Blank }
\addcontentsline{toc}{subsection}{Have Patience When Starting the Daemons or
Mounting Blank Tapes}

When you start the Bacula daemons, the Storage daemon attempts to open all
defined storage devices and verify the currently mounted Volume (if
configured). Until all the storage devices are verified, the Storage daemon
will not accept connections from the Console program. If a tape was previously
used, it will be rewound, and on some devices this can take several minutes.
As a consequence, you may need to have a bit of patience when first contacting
the Storage daemon after starting the daemons. If you can see your tape drive,
once the lights stop flashing, the drive will be ready to be used. 

The same considerations apply if you have just mounted a blank tape in a drive
such as an HP DLT. It can take a minute or two before the drive properly
recognizes that the tape is blank. If you attempt to {\bf mount} the tape with
the Console program during this recognition period, it is quite possible that
you will hang your SCSI driver (at least on my RedHat Linux system). As a
consequence, you are again urged to have patience when inserting blank tapes.
Let the device settle down before attempting to access it. 

\subsection*{Difficulties Connecting from the FD to the SD}
\index[general]{Difficulties Connecting from the FD to the SD }
\index[general]{SD!Difficulties Connecting from the FD to the }
\addcontentsline{toc}{subsection}{Difficulties Connecting from the FD to the
SD}

If you are having difficulties getting one or more of your File daemons to
connect to the Storage daemon, it is most likely because you have not used a
fully qualified domain name on the {\bf Address} directive in the
Director's Storage resource. That is the resolver on the File daemon's machine
(not on the Director's) must be able to resolve the name you supply into an IP
address. An example of an address that is guaranteed not to work: {\bf
localhost}. An example that may work: {\bf megalon}. An example that is more
likely to work: {\bf magalon.mydomain.com}. On Win32 if you don't have a good
resolver (often true on older Win98 systems), you might try using an IP
address in place of a name. 

If your address is correct, then make sure that no other program is using the
port 9103 on the Storage daemon's machine. The Bacula port number are
authorized by IANA, and should not be used by other programs, but apparently
some HP printers do use these port numbers. A {\bf netstat -a} on the Storage
daemon's machine can determine who is using the 9103 port (used for FD to SD
communications in Bacula). 

\subsection*{Daemon Command Line Options}
\index[general]{Daemon Command Line Options }
\index[general]{Options!Daemon Command Line }
\addcontentsline{toc}{subsection}{Daemon Command Line Options}

Each of the three daemons (Director, File, Storage) accepts a small set of
options on the command line. In general, each of the daemons as well as the
Console program accepts the following options: 

\begin{description}

\item [-c \lt{}file\gt{}]
   \index[sd]{-c \lt{}file\gt{} }
   Define the file to use as a  configuration file. The default is the daemon
name followed  by {\bf .conf} i.e. {\bf bacula-dir.conf} for the Director, 
{\bf bacula-fd.conf} for the File daemon, and {\bf bacula-sd}  for the Storage
daemon.  

\item [-d nn]
   \index[sd]{-d nn }
   Set the debug level to {\bf nn}. Higher levels  of debug cause more
information to be displayed on STDOUT concerning  what the daemon is doing.  

\item [-f]
   Run the daemon in the foreground. This option is  needed to run the daemon
   under the debugger.  

\item [-s]
   Do not trap signals. This option is needed to run  the daemon under the
   debugger.  

\item [-t]
   Read the configuration file and print any error messages,  then immediately
   exit. Useful for syntax testing of  new configuration files.  

\item [-v]
   Be more verbose or more complete in printing error  and informational
   messages. Recommended.  

\item [-?]
   Print the version and list of options. 
   \end{description}

The Director has the following additional Director specific option: 

\begin{description}

\item [-r \lt{}job\gt{}]
   \index[fd]{-r \lt{}job\gt{} }
   Run the named job immediately. This is  for debugging and should not be used. 
\end{description}

The File daemon has the following File daemon specific option: 

\begin{description}

\item [-i]
   Assume that the daemon is called from {\bf inetd}  or {\bf xinetd}. In this
   case, the daemon assumes that a connection  has already been made and that it
is passed as STDIN. After the  connection terminates the daemon will exit. 
\end{description}

The Storage daemon has no Storage daemon specific options. 

The Console program has no console specific options. 

\subsection*{Creating a Pool}
\label{Pool}
\index[general]{Pool!Creating a }
\index[general]{Creating a Pool }
\addcontentsline{toc}{subsection}{Creating a Pool}

Creating the Pool is automatically done when {\bf Bacula} starts, so if you
understand Pools, you can skip to the next section. 

When you run a job, one of the things that Bacula must know is what Volumes to
use to backup the FileSet. Instead of specifying a Volume (tape) directly, you
specify which Pool of Volumes you want Bacula to consult when it wants a tape
for writing backups. Bacula will select the first available Volume from the
Pool that is appropriate for the Storage device you have specified for the Job
being run. When a volume has filled up with data, {\bf Bacula} will change its
VolStatus from {\bf Append} to {\bf Full}, and then {\bf Bacula} will use the
next volume and so on. If no appendable Volume exists in the Pool, the
Director will attempt to recycle an old Volume, if there are still no
appendable Volumes available, {\bf Bacula} will send a message requesting the
operator to create an appropriate Volume. 

{\bf Bacula} keeps track of the Pool name, the volumes contained in the Pool,
and a number of attributes of each of those Volumes. 

When Bacula starts, it ensures that all Pool resource definitions have been
recorded in the catalog. You can verify this by entering: 

\footnotesize
\begin{verbatim}
list pools
\end{verbatim}
\normalsize

to the console program, which should print something like the following: 

\footnotesize
\begin{verbatim}
*list pools
Using default Catalog name=MySQL DB=bacula
+--------+---------+---------+---------+----------+-------------+
| PoolId | Name    | NumVols | MaxVols | PoolType | LabelFormat |
+--------+---------+---------+---------+----------+-------------+
| 1      | Default | 3       | 0       | Backup   | *           |
| 2      | File    | 12      | 12      | Backup   | File        |
+--------+---------+---------+---------+----------+-------------+
*
\end{verbatim}
\normalsize

If you attempt to create the same Pool name a second time, {\bf Bacula} will
print: 

\footnotesize
\begin{verbatim}
Error: Pool Default already exists.
Once created, you may use the {\bf update} command to
modify many of the values in the Pool record.
\end{verbatim}
\normalsize

\label{Labeling}

\subsection*{Labeling Your Volumes}
\index[general]{Volumes!Labeling Your }
\index[general]{Labeling Your Volumes }
\addcontentsline{toc}{subsection}{Labeling Your Volumes}

Bacula requires that each Volume contains a software label. There are several
strategies for labeling volumes. The one I use is to label them as they are
needed by {\bf Bacula} using the console program. That is when Bacula needs a
new Volume, and it does not find one in the catalog, it will send me an email
message requesting that I add Volumes to the Pool. I then use the {\bf label}
command in the Console program to label a new Volume and to define it in the
Pool database, after which Bacula will begin writing on the new Volume.
Alternatively, I can use the Console {\bf relabel} command to relabel a Volume
that is no longer used providing it has VolStatus {\bf Purged}. 

Another strategy is to label a set of volumes at the start, then use them as
{\bf Bacula} requests them. This is most often done if you are cycling through
a set of tapes, for example using an autochanger. For more details on
recycling, please see the 
\ilink{Automatic Volume Recycling}{_ChapterStart22} chapter of
this manual. 

If you run a Bacula job, and you have no labeled tapes in the Pool, Bacula
will inform you, and you can create them "on-the-fly" so to speak. In my
case, I label my tapes with the date, for example: {\bf DLT-18April02}. See
below for the details of using the {\bf label} command. 

\subsection*{Labeling Volumes with the Console Program}
\index[general]{Labeling Volumes with the Console Program }
\index[general]{Program!Labeling Volumes with the Console }
\addcontentsline{toc}{subsection}{Labeling Volumes with the Console Program}

Labeling volumes is normally done by using the console program. 

\begin{enumerate}
\item ./bconsole  
\item label 
   \end{enumerate}

If Bacula complains that you cannot label the tape because it is already
labeled, simply {\bf unmount} the tape using the {\bf unmount} command in the
console, then physically mount a blank tape and re-issue the {\bf label}
command. 

Since the physical storage media is different for each device, the {\bf label}
command will provide you with a list of the defined Storage resources such as
the following: 

\footnotesize
\begin{verbatim}
The defined Storage resources are:
     1: File
     2: 8mmDrive
     3: DLTDrive
     4: SDT-10000
Select Storage resource (1-4):
\end{verbatim}
\normalsize

At this point, you should have a blank tape in the drive corresponding to the
Storage resource that you select. 

It will then ask you for the Volume name. 

\footnotesize
\begin{verbatim}
Enter new Volume name:
\end{verbatim}
\normalsize

If Bacula complains: 

\footnotesize
\begin{verbatim}
Media record for Volume xxxx already exists.
\end{verbatim}
\normalsize

It means that the volume name {\bf xxxx} that you entered already exists in
the Media database. You can list all the defined Media (Volumes) with the {\bf
list media} command. Note, the LastWritten column has been truncated for
proper printing. 

\footnotesize
\begin{verbatim}
+---------------+---------+--------+----------------+-----/~/-+------------+-----+
| VolumeName    | MediaTyp| VolStat| VolBytes       | LastWri | VolReten   | Recy|
+---------------+---------+--------+----------------+---------+------------+-----+
| DLTVol0002    | DLT8000 | Purged | 56,128,042,217 | 2001-10 | 31,536,000 |   0 |
| DLT-07Oct2001 | DLT8000 | Full   | 56,172,030,586 | 2001-11 | 31,536,000 |   0 |
| DLT-08Nov2001 | DLT8000 | Full   | 55,691,684,216 | 2001-12 | 31,536,000 |   0 |
| DLT-01Dec2001 | DLT8000 | Full   | 55,162,215,866 | 2001-12 | 31,536,000 |   0 |
| DLT-28Dec2001 | DLT8000 | Full   | 57,888,007,042 | 2002-01 | 31,536,000 |   0 |
| DLT-20Jan2002 | DLT8000 | Full   | 57,003,507,308 | 2002-02 | 31,536,000 |   0 |
| DLT-16Feb2002 | DLT8000 | Full   | 55,772,630,824 | 2002-03 | 31,536,000 |   0 |
| DLT-12Mar2002 | DLT8000 | Full   | 50,666,320,453 | 1970-01 | 31,536,000 |   0 |
| DLT-27Mar2002 | DLT8000 | Full   | 57,592,952,309 | 2002-04 | 31,536,000 |   0 |
| DLT-15Apr2002 | DLT8000 | Full   | 57,190,864,185 | 2002-05 | 31,536,000 |   0 |
| DLT-04May2002 | DLT8000 | Full   | 60,486,677,724 | 2002-05 | 31,536,000 |   0 |
| DLT-26May02   | DLT8000 | Append |  1,336,699,620 | 2002-05 | 31,536,000 |   1 |
+---------------+---------+--------+----------------+-----/~/-+------------+-----+
\end{verbatim}
\normalsize

Once Bacula has verified that the volume does not already exist, it will
prompt you for the name of the Pool in which the Volume (tape) is to be
created.  If there is only one Pool (Default), it will be automatically
selected.

If the tape is successfully labeled, a Volume record will also be created in
the Pool. That is the Volume name and all its other attributes will appear
when you list the Pool. In addition, that Volume will be available for backup
if the MediaType matches what is requested by the Storage daemon. 

When you labeled the tape, you answered very few questions about it --
principally the Volume name, and perhaps the Slot. However, a Volume record in
the catalog database (internally known as a Media record) contains quite a few
attributes. Most of these attributes will be filled in from the default values
that were defined in the Pool (i.e. the Pool holds most of the default
attributes used when creating a Volume). 

It is also possible to add media to the pool without physically labeling the
Volumes. This can be done with the {\bf add} command. For more information,
please see the 
\ilink{Console Chapter}{_ConsoleChapter} of this manual. 
