1%% 2%% 3\chapter{The Restore Command} 4\label{RestoreChapter} 5\index[general]{Command!Console Restore} 6\index[general]{Console Restore Command} 7 8\section{General} 9\index[general]{General } 10 11Below, we will discuss restoring files with the Console {\bf restore} command, 12which is the recommended way of doing restoring files. It is not possible 13to restore files by automatically starting a job as you do with Backup, 14Verify, ... jobs. However, in addition to the console restore command, 15there is a standalone program named {\bf bextract}, which also permits 16restoring files. For more information on this program, please see the 17\ilink{Bacula Utility Programs}{bextract} chapter of this manual. We 18don't particularly recommend the {\bf bextract} program because it 19lacks many of the features of the normal Bacula restore, such as the 20ability to restore Win32 files to Unix systems, and the ability to 21restore access control lists (ACL). As a consequence, we recommend, 22wherever possible to use Bacula itself for restores as described below. 23 24You may also want to look at the {\bf bls} program in the same chapter, 25which allows you to list the contents of your Volumes. Finally, if you 26have an old Volume that is no longer in the catalog, you can restore the 27catalog entries using the program named {\bf bscan}, documented in the same 28\ilink{Bacula Utility Programs}{bscan} chapter. 29 30In general, to restore a file or a set of files, you must run a {\bf restore} 31job. That is a job with {\bf Type = Restore}. As a consequence, you will need 32a predefined {\bf restore} job in your {\bf bacula-dir.conf} (Director's 33config) file. The exact parameters (Client, FileSet, ...) that you define are 34not important as you can either modify them manually before running the job or 35if you use the {\bf restore} command, explained below, Bacula will 36automatically set them for you. In fact, you can no longer simply run a restore 37job. You must use the restore command. 38 39Since Bacula is a network backup program, you must be aware that when you 40restore files, it is up to you to ensure that you or Bacula have selected the 41correct Client and the correct hard disk location for restoring those files. 42{\bf Bacula} will quite willingly backup client A, and restore it by sending 43the files to a different directory on client B. Normally, you will want to 44avoid this, but assuming the operating systems are not too different in their 45file structures, this should work perfectly well, if so desired. 46By default, Bacula will restore data to the same Client that was backed 47up, and those data will be restored not to the original places but to 48{\bf /tmp/bacula-restores}. You may modify any of these defaults when the 49restore command prompts you to run the job by selecting the {\bf mod} 50option. 51 52\label{Example1} 53\section{The Restore Command} 54\index[general]{Command!Restore} 55\index[general]{Restore Command} 56 57Since Bacula maintains a catalog of your files and on which Volumes (disk or 58tape), they are stored, it can do most of the bookkeeping work, allowing you 59simply to specify what kind of restore you want (current, before a particular 60date), and what files to restore. Bacula will then do the rest. 61 62This is accomplished using the {\bf restore} command in the Console. First you 63select the kind of restore you want, then the JobIds are selected, 64the File records for those Jobs are placed in an internal Bacula directory 65tree, and the restore enters a file selection mode that allows you to 66interactively walk up and down the file tree selecting individual files to be 67restored. This mode is somewhat similar to the standard Unix {\bf restore} 68program's interactive file selection mode. 69 70If a Job's file records have been pruned from the catalog, the {\bf restore} 71command will be unable to find any files to restore. Bacula will ask if you 72want to restore all of them or if you want to use a regular expression to 73restore only a selection while reading media. See \ilink{FileRegex 74 option}{FileRegex} and below for more details on this. 75 76Within the Console program, after entering the {\bf restore} command, you are 77presented with the following selection prompt: 78 79\footnotesize 80\begin{verbatim} 81First you select one or more JobIds that contain files 82to be restored. You will be presented several methods 83of specifying the JobIds. Then you will be allowed to 84select which files from those JobIds are to be restored. 85To select the JobIds, you have the following choices: 86 1: List last 20 Jobs run 87 2: List Jobs where a given File is saved 88 3: Enter list of comma separated JobIds to select 89 4: Enter SQL list command 90 5: Select the most recent backup for a client 91 6: Select backup for a client before a specified time 92 7: Enter a list of files to restore 93 8: Enter a list of files to restore before a specified time 94 9: Find the JobIds of the most recent backup for a client 95 10: Find the JobIds for a backup for a client before a specified time 96 11: Enter a list of directories to restore for found JobIds 97 12: Cancel 98Select item: (1-12): 99\end{verbatim} 100\normalsize 101 102There are a lot of options, and as a point of reference, most people will 103want to slect item 5 (the most recent backup for a client). The details 104of the above options are: 105 106\begin{itemize} 107\item Item 1 will list the last 20 jobs run. If you find the Job you want, 108 you can then select item 3 and enter its JobId(s). 109 110\item Item 2 will list all the Jobs where a specified file is saved. If you 111 find the Job you want, you can then select item 3 and enter the JobId. 112 113\item Item 3 allows you the enter a list of comma separated JobIds whose 114 files will be put into the directory tree. You may then select which 115 files from those JobIds to restore. Normally, you would use this option 116 if you have a particular version of a file that you want to restore and 117 you know its JobId. The most common options (5 and 6) will not select 118 a job that did not terminate normally, so if you know a file is 119 backed up by a Job that failed (possibly because of a system crash), you 120 can access it through this option by specifying the JobId. 121 122\item Item 4 allows you to enter any arbitrary SQL command. This is 123 probably the most primitive way of finding the desired JobIds, but at 124 the same time, the most flexible. Once you have found the JobId(s), you 125 can select item 3 and enter them. 126 127\item Item 5 will automatically select the most recent Full backup and all 128 subsequent incremental and differential backups for a specified Client. 129 These are the Jobs and Files which, if reloaded, will restore your 130 system to the most current saved state. It automatically enters the 131 JobIds found into the directory tree in an optimal way such that only 132 the most recent copy of any particular file found in the set of Jobs 133 will be restored. This is probably the most convenient of all the above 134 options to use if you wish to restore a selected Client to its most 135 recent state. 136 137 There are two important things to note. First, this automatic selection 138 will never select a job that failed (terminated with an error status). 139 If you have such a job and want to recover one or more files from it, 140 you will need to explicitly enter the JobId in item 3, then choose the 141 files to restore. 142 143 If some of the Jobs that are needed to do the restore have had their 144 File records pruned, the restore will be incomplete. Bacula currently 145 does not correctly detect this condition. You can however, check for 146 this by looking carefully at the list of Jobs that Bacula selects and 147 prints. If you find Jobs with the JobFiles column set to zero, when 148 files should have been backed up, then you should expect problems. 149 150 If all the File records have been pruned, Bacula will realize that there 151 are no file records in any of the JobIds chosen and will inform you. It 152 will then propose doing a full restore (non-selective) of those JobIds. 153 This is possible because Bacula still knows where the beginning of the 154 Job data is on the Volumes, even if it does not know where particular 155 files are located or what their names are. 156 157\item Item 6 allows you to specify a date and time, after which Bacula will 158 automatically select the most recent Full backup and all subsequent 159 incremental and differential backups that started before the specified date 160 and time. 161 162\item Item 7 allows you to specify one or more filenames (complete path 163 required) to be restored. Each filename is entered one at a time or if you 164 prefix a filename with the less-than symbol (\lt{}) Bacula will read that 165 file and assume it is a list of filenames to be restored. If you 166 prefix the filename with a question mark (?), then the filename will 167 be interpreted as an SQL table name, and Bacula will include the rows 168 of that table in the list to be restored. The table must contain the 169 JobId in the first column and the FileIndex in the second column. 170 This table feature is intended for external programs that want to build 171 their own list of files to be restored. 172 The filename entry mode is terminated by entering a blank line. 173 174\item Item 8 allows you to specify a date and time before entering the 175 filenames. See Item 7 above for more details. 176 177\item Item 9 allows you find the JobIds of the most recent backup for 178 a client. This is much like option 5 (it uses the same code), but 179 those JobIds are retained internally as if you had entered them 180 manually. You may then select item 11 (see below) to restore one 181 or more directories. 182 183\item Item 10 is the same as item 9, except that it allows you to enter 184 a before date (as with item 6). These JobIds will then be retained 185 internally. 186 187\index[general]{Restore Directories} 188\item Item 11 allows you to enter a list of JobIds from which you can 189 select directories to be restored. The list of JobIds can have been 190 previously created by using either item 9 or 10 on the menu. You 191 may then enter a full path to a directory name or a filename preceded 192 by a less than sign (\lt{}). The filename should contain a list 193 of directories to be restored. All files in those directories will 194 be restored, but if the directory contains subdirectories, nothing 195 will be restored in the subdirectory unless you explicitly enter its 196 name. 197 198\item Item 12 allows you to cancel the restore command. 199\end{itemize} 200 201As an example, suppose that we select item 5 (restore to most recent state). 202If you have not specified a client=xxx on the command line, it 203it will then ask for the desired Client, which on my system, will print all 204the Clients found in the database as follows: 205 206\footnotesize 207\begin{verbatim} 208Defined clients: 209 1: Rufus 210 2: Matou 211 3: Polymatou 212 4: Minimatou 213 5: Minou 214 6: MatouVerify 215 7: PmatouVerify 216 8: RufusVerify 217 9: Watchdog 218Select Client (File daemon) resource (1-9): 219\end{verbatim} 220\normalsize 221 222You will probably have far fewer Clients than this example, and if you have 223only one Client, it will be automatically selected. In this case, I enter 224{\bf Rufus} to select the Client. Then Bacula needs to know what FileSet is 225to be restored, so it prompts with: 226 227\footnotesize 228\begin{verbatim} 229The defined FileSet resources are: 230 1: Full Set 231 2: Other Files 232Select FileSet resource (1-2): 233\end{verbatim} 234\normalsize 235 236If you have only one FileSet defined for the Client, it will be selected 237automatically. I choose item 1, which is my full backup. Normally, you 238will only have a single FileSet for each Job, and if your machines are 239similar (all Linux) you may only have one FileSet for all your Clients. 240 241At this point, {\bf Bacula} has all the information it needs to find the most 242recent set of backups. It will then query the database, which may take a bit 243of time, and it will come up with something like the following. Note, some of 244the columns are truncated here for presentation: 245 246\footnotesize 247\begin{verbatim} 248+-------+------+----------+-------------+-------------+------+-------+------------+ 249| JobId | Levl | JobFiles | StartTime | VolumeName | File | SesId |VolSesTime | 250+-------+------+----------+-------------+-------------+------+-------+------------+ 251| 1,792 | F | 128,374 | 08-03 01:58 | DLT-19Jul02 | 67 | 18 | 1028042998 | 252| 1,792 | F | 128,374 | 08-03 01:58 | DLT-04Aug02 | 0 | 18 | 1028042998 | 253| 1,797 | I | 254 | 08-04 13:53 | DLT-04Aug02 | 5 | 23 | 1028042998 | 254| 1,798 | I | 15 | 08-05 01:05 | DLT-04Aug02 | 6 | 24 | 1028042998 | 255+-------+------+----------+-------------+-------------+------+-------+------------+ 256You have selected the following JobId: 1792,1792,1797 257Building directory tree for JobId 1792 ... 258Building directory tree for JobId 1797 ... 259Building directory tree for JobId 1798 ... 260cwd is: / 261$ 262\end{verbatim} 263\normalsize 264 265Depending on the number of {\bf JobFiles} for each JobId, the {\bf Building 266directory tree ..."} can take a bit of time. If you notice ath all the 267JobFiles are zero, your Files have probably been pruned and you will not be 268able to select any individual files -- it will be restore everything or 269nothing. 270 271In our example, Bacula found four Jobs that comprise the most recent backup of 272the specified Client and FileSet. Two of the Jobs have the same JobId because 273that Job wrote on two different Volumes. The third Job was an incremental 274backup to the previous Full backup, and it only saved 254 Files compared to 275128,374 for the Full backup. The fourth Job was also an incremental backup 276that saved 15 files. 277 278Next Bacula entered those Jobs into the directory tree, with no files marked 279to be restored as a default, tells you how many files are in the tree, and 280tells you that the current working directory ({\bf cwd}) is /. Finally, Bacula 281prompts with the dollar sign (\$) to indicate that you may enter commands to 282move around the directory tree and to select files. 283 284If you want all the files to automatically be marked when the directory 285tree is built, you could have entered the command {\bf restore all}, or 286at the \$ prompt, you can simply enter {\bf mark *}. 287 288Instead of choosing item 5 on the first menu (Select the most recent backup 289for a client), if we had chosen item 3 (Enter list of JobIds to select) and we 290had entered the JobIds {\bf 1792,1797,1798} we would have arrived at the same 291point. 292 293One point to note, if you are manually entering JobIds, is that you must enter 294them in the order they were run (generally in increasing JobId order). If you 295enter them out of order and the same file was saved in two or more of the 296Jobs, you may end up with an old version of that file (i.e. not the most 297recent). 298 299Directly entering the JobIds can also permit you to recover data from 300a Job that wrote files to tape but that terminated with an error status. 301 302While in file selection mode, you can enter {\bf help} or a question mark (?) 303to produce a summary of the available commands: 304 305\footnotesize 306\begin{verbatim} 307 Command Description 308 ======= =========== 309 cd change current directory 310 count count marked files in and below the cd 311 dir long list current directory, wildcards allowed 312 done leave file selection mode 313 estimate estimate restore size 314 exit same as done command 315 find find files, wildcards allowed 316 help print help 317 ls list current directory, wildcards allowed 318 lsmark list the marked files in and below the cd 319 mark mark dir/file to be restored recursively in dirs 320 markdir mark directory name to be restored (no files) 321 pwd print current working directory 322 unmark unmark dir/file to be restored recursively in dir 323 unmarkdir unmark directory name only no recursion 324 quit quit and do not do restore 325 ? print help 326\end{verbatim} 327\normalsize 328 329As a default no files have been selected for restore (unless you 330added {\bf all} to the command line. If you want to restore 331everything, at this point, you should enter {\bf mark *}, and then {\bf done} 332and {\bf Bacula} will write the bootstrap records to a file and request your 333approval to start a restore job. 334 335If you do not enter the above mentioned {\bf mark *} command, you will start 336with an empty slate. Now you can simply start looking at the tree and {\bf 337mark} particular files or directories you want restored. It is easy to make 338a mistake in specifying a file to mark or unmark, and Bacula's error handling 339is not perfect, so please check your work by using the {\bf ls} or {\bf dir} 340commands to see what files are actually selected. Any selected file has its 341name preceded by an asterisk. 342 343To check what is marked or not marked, enter the {\bf count} command, which 344displays: 345 346\footnotesize 347\begin{verbatim} 348128401 total files. 128401 marked to be restored. 349 350\end{verbatim} 351\normalsize 352 353Each of the above commands will be described in more detail in the next 354section. We continue with the above example, having accepted to restore all 355files as Bacula set by default. On entering the {\bf done} command, Bacula 356prints: 357 358\footnotesize 359\begin{verbatim} 360Bootstrap records written to /home/kern/bacula/working/restore.bsr 361The job will require the following 362 Volume(s) Storage(s) SD Device(s) 363=========================================================================== 364 365 DLT-19Jul02 Tape DLT8000 366 DLT-04Aug02 Tape DLT8000 367 368128401 files selected to restore. 369Run Restore job 370JobName: kernsrestore 371Bootstrap: /home/kern/bacula/working/restore.bsr 372Where: /tmp/bacula-restores 373Replace: always 374FileSet: Other Files 375Client: Rufus 376Storage: Tape 377When: 2006-12-11 18:20:33 378Catalog: MyCatalog 379Priority: 10 380OK to run? (yes/mod/no): 381 382\end{verbatim} 383\normalsize 384 385Please examine each of the items very carefully to make sure that they are 386correct. In particular, look at {\bf Where}, which tells you where in the 387directory structure the files will be restored, and {\bf Client}, which 388tells you which client will receive the files. Note that by default the 389Client which will receive the files is the Client that was backed up. 390These items will not always be completed with the correct values depending 391on which of the restore options you chose. You can change any of these 392default items by entering {\bf mod} and responding to the prompts. 393 394The above assumes that you have defined a {\bf Restore} Job resource in your 395Director's configuration file. Normally, you will only need one Restore Job 396resource definition because by its nature, restoring is a manual operation, 397and using the Console interface, you will be able to modify the Restore Job to 398do what you want. 399 400An example Restore Job resource definition is given below. 401 402Returning to the above example, you should verify that the Client name is 403correct before running the Job. However, you may want to modify some of the 404parameters of the restore job. For example, in addition to checking the Client 405it is wise to check that the Storage device chosen by Bacula is indeed 406correct. Although the {\bf FileSet} is shown, it will be ignored in restore. 407The restore will choose the files to be restored either by reading the {\bf 408Bootstrap} file, or if not specified, it will restore all files associated 409with the specified backup {\bf JobId} (i.e. the JobId of the Job that 410originally backed up the files). 411 412Finally before running the job, please note that the default location for 413restoring files is {\bf not} their original locations, but rather the directory 414{\bf /tmp/bacula-restores}. You can change this default by modifying your {\bf 415bacula-dir.conf} file, or you can modify it using the {\bf mod} option. If you 416want to restore the files to their original location, you must have {\bf 417Where} set to nothing or to the root, i.e. {\bf /}. 418 419If you now enter {\bf yes}, Bacula will run the restore Job. The Storage 420daemon will first request Volume {\bf DLT-19Jul02} and after the appropriate 421files have been restored from that volume, it will request Volume {\bf 422DLT-04Aug02}. 423 424\subsection{Restore a pruned job using a pattern} 425 During a restore, if all File records are pruned from the catalog 426 for a Job, normally Bacula can restore only all files saved. That 427 is there is no way using the catalog to select individual files. 428 With this new feature, Bacula will ask if you want to specify a Regex 429 expression for extracting only a part of the full backup. 430 431\begin{verbatim} 432 Building directory tree for JobId(s) 1,3 ... 433 There were no files inserted into the tree, so file selection 434 is not possible.Most likely your retention policy pruned the files 435 436 Do you want to restore all the files? (yes|no): no 437 438 Regexp matching files to restore? (empty to abort): /tmp/regress/(bin|tests)/ 439 Bootstrap records written to /tmp/regress/working/zog4-dir.restore.1.bsr 440\end{verbatim} 441 442 See also \ilink{FileRegex bsr option}{FileRegex} for more information. 443 444\section{Selecting Files by Filename} 445\index[general]{Selecting Files by Filename } 446\index[general]{Filename!Selecting Files by } 447 448If you have a small number of files to restore, and you know the filenames, 449you can either put the list of filenames in a file to be read by Bacula, or 450you can enter the names one at a time. The filenames must include the full 451path and filename. No wild cards are used. 452 453To enter the files, after the {\bf restore}, you select item number 7 from the 454prompt list: 455 456\footnotesize 457\begin{verbatim} 458To select the JobIds, you have the following choices: 459 1: List last 20 Jobs run 460 2: List Jobs where a given File is saved 461 3: Enter list of comma separated JobIds to select 462 4: Enter SQL list command 463 5: Select the most recent backup for a client 464 6: Select backup for a client before a specified time 465 7: Enter a list of files to restore 466 8: Enter a list of files to restore before a specified time 467 9: Find the JobIds of the most recent backup for a client 468 10: Find the JobIds for a backup for a client before a specified time 469 11: Enter a list of directories to restore for found JobIds 470 12: Cancel 471Select item: (1-12): 472\end{verbatim} 473\normalsize 474 475which then prompts you for the client name: 476 477\footnotesize 478\begin{verbatim} 479Defined Clients: 480 1: Timmy 481 2: Tibs 482 3: Rufus 483Select the Client (1-3): 3 484\end{verbatim} 485\normalsize 486 487Of course, your client list will be different, and if you have only one 488client, it will be automatically selected. And finally, Bacula requests you to 489enter a filename: 490 491\footnotesize 492\begin{verbatim} 493Enter filename: 494\end{verbatim} 495\normalsize 496 497At this point, you can enter the full path and filename 498 499\footnotesize 500\begin{verbatim} 501Enter filename: /home/kern/bacula/k/Makefile.in 502Enter filename: 503\end{verbatim} 504\normalsize 505 506as you can see, it took the filename. If Bacula cannot find a copy of the 507file, it prints the following: 508 509\footnotesize 510\begin{verbatim} 511Enter filename: junk filename 512No database record found for: junk filename 513Enter filename: 514\end{verbatim} 515\normalsize 516 517If you want Bacula to read the filenames from a file, you simply precede the 518filename with a less-than symbol (\lt{}). When you have entered all the 519filenames, you enter a blank line, and Bacula will write the bootstrap file, 520tells you what tapes will be used, and proposes a Restore job to be run: 521 522\footnotesize 523\begin{verbatim} 524Enter filename: 525Automatically selected Storage: DDS-4 526Bootstrap records written to /home/kern/bacula/working/restore.bsr 527The restore job will require the following Volumes: 528 529 test1 5301 file selected to restore. 531Run Restore job 532JobName: kernsrestore 533Bootstrap: /home/kern/bacula/working/restore.bsr 534Where: /tmp/bacula-restores 535Replace: always 536FileSet: Other Files 537Client: Rufus 538Storage: DDS-4 539When: 2003-09-11 10:20:53 540Priority: 10 541OK to run? (yes/mod/no): 542\end{verbatim} 543\normalsize 544 545It is possible to automate the selection by file by putting your list of files 546in say {\bf /tmp/file-list}, then using the following command: 547 548\footnotesize 549\begin{verbatim} 550restore client=Rufus file=</tmp/file-list 551\end{verbatim} 552\normalsize 553 554If in modifying the parameters for the Run Restore job, you find that Bacula 555asks you to enter a Job number, this is because you have not yet specified 556either a Job number or a Bootstrap file. Simply entering zero will allow you 557to continue and to select another option to be modified. 558 559\label{Replace} 560 561\section{Replace Options} 562 563When restoring, you have the option to specify a Replace option. This 564directive determines the action to be taken when restoring a file or 565directory that already exists. This directive can be set by selecting 566the {\bf mod} option. You will be given a list of parameters to choose 567from. Full details on this option can be found in the Job Resource section 568of the Director documentation. 569 570\label{CommandArguments} 571 572\section{Command Line Arguments} 573\index[general]{Arguments!Command Line } 574\index[general]{Command Line Arguments } 575 576If all the above sounds complicated, you will probably agree that it really 577isn't after trying it a few times. It is possible to do everything that was 578shown above, with the exception of selecting the FileSet, by using command 579line arguments with a single command by entering: 580 581\footnotesize 582\begin{verbatim} 583restore client=Rufus select current all done yes 584\end{verbatim} 585\normalsize 586 587The {\bf client=Rufus} specification will automatically select Rufus as the 588client, the {\bf current} tells Bacula that you want to restore the system to 589the most current state possible, and the {\bf yes} suppresses the final {\bf 590yes/mod/no} prompt and simply runs the restore. 591 592The full list of possible command line arguments are: 593 594\begin{itemize} 595\item {\bf all} -- select all Files to be restored. 596\item {\bf select} -- use the tree selection method. 597\item {\bf done} -- do not prompt the user in tree mode. 598\item {\bf current} -- automatically select the most current set of backups 599 for the specified client. 600\item {\bf client=xxxx} -- initially specifies the client from which the 601 backup was made and the client to which the restore will be make. See also 602 "restoreclient" keyword. 603\item {\bf restoreclient=xxxx} -- if the keyword is specified, then the 604 restore is written to that client. 605\item {\bf jobid=nnn} -- specify a JobId or comma separated list of JobIds to 606 be restored. 607\item {\bf before=YYYY-MM-DD HH:MM:SS} -- specify a date and time to which 608 the system should be restored. Only Jobs started before the specified 609 date/time will be selected, and as is the case for {\bf current} Bacula will 610 automatically find the most recent prior Full save and all Differential and 611 Incremental saves run before the date you specify. Note, this command is not 612 too user friendly in that you must specify the date/time exactly as shown. 613\item {\bf file=filename} -- specify a filename to be restored. You must 614 specify the full path and filename. Prefixing the entry with a less-than 615 sign 616 (\lt{}) will cause Bacula to assume that the filename is on your system and 617 contains a list of files to be restored. Bacula will thus read the list from 618 that file. Multiple file=xxx specifications may be specified on the command 619 line. 620\item {\bf jobid=nnn} -- specify a JobId to be restored. 621\item {\bf pool=pool-name} -- specify a Pool name to be used for selection of 622 Volumes when specifying options 5 and 6 (restore current system, and restore 623 current system before given date). This permits you to have several Pools, 624 possibly one offsite, and to select the Pool to be used for restoring. 625\item {\bf where=/tmp/bacula-restore} -- restore files in {\bf where} directory. 626\item {\bf yes} -- automatically run the restore without prompting for 627 modifications (most useful in batch scripts). 628\item {\bf strip\_prefix=/prod} -- remove a part of the filename when restoring. 629\item {\bf add\_prefix=/test} -- add a prefix to all files when restoring (like 630 where) (can't be used with {\bf where=}). 631\item {\bf add\_suffix=.old} -- add a suffix to all your files. 632\item {\bf regexwhere=!a.pdf!a.bkp.pdf!} -- do complex filename manipulation 633 like with sed unix command. Will overwrite other filename manipulation. 634\end{itemize} 635 636\label{restorefilerelocation} 637\section{Using File Relocation} 638\index[general]{Using File Relocation} 639\label{filerelocation} 640 641\subsection{Introduction} 642 643The \textbf{where=} option is simple, but not very powerful. With file 644relocation, Bacula can restore a file to the same directory, but with a 645different name, or in an other directory without recreating the full path. 646 647You can also do filename and path manipulations, implemented in Bacula 6482.1.8 or later, such as adding a suffix to all your files, renaming files 649or directories, etc. Theses options will overwrite {\bf where=} option. 650 651 652For example, many users use OS snapshot features so that file 653\texttt{/home/eric/mbox} will be backed up from the directory 654\texttt{/.snap/home/eric/mbox}, which can complicate restores. If you use 655\textbf{where=/tmp}, the file will be restored to 656\texttt{/tmp/.snap/home/eric/mbox} and you will have to move the file to 657\texttt{/home/eric/mbox.bkp} by hand. 658 659However, case, you could use the 660\textbf{strip\_prefix=/.snap} and \textbf{add\_suffix=.bkp} options and 661Bacula will restore the file to its original location -- that is 662\texttt{/home/eric/mbox}. 663 664To use this feature, there are command line options as described in 665the \ilink{restore section}{restorefilerelocation} of this manual; 666you can modify your restore job before running it; or you can 667add options to your restore job in as described in 668\ilink{bacula-dir.conf}{confaddprefix}. 669 670\begin{verbatim} 671Parameters to modify: 672 1: Level 673 2: Storage 674 ... 675 10: File Relocation 676 ... 677Select parameter to modify (1-12): 678 679 680This will replace your current Where value 681 1: Strip prefix 682 2: Add prefix 683 3: Add file suffix 684 4: Enter a regexp 685 5: Test filename manipulation 686 6: Use this ? 687Select parameter to modify (1-6): 688\end{verbatim} 689 690 691\subsection{RegexWhere Format} 692 693The format is very close to that used by sed or Perl (\texttt{s/replace this/by 694 that/}) operator. A valid regexwhere expression has three fields : 695\begin{itemize} 696\item a search expression (with optionnal submatch) 697\item a replacement expression (with optionnal back references \$1 to \$9) 698\item a set of search options (only case-insensitive ``i'' at this time) 699\end{itemize} 700 701Each field is delimited by a separator specified by the user as the first 702character of the expression. The separator can be one of the following: 703\begin{verbatim} 704<separator-keyword> = / ! ; % : , ~ # = & 705\end{verbatim} 706 707You can use several expressions separated by a commas. 708 709\subsection*{Examples} 710 711\begin{tabular}{|c|c|c|l|} 712\hline 713Orignal filename & New filename & RegexWhere & Comments \\ 714\hline 715\hline 716\texttt{c:/system.ini} & \texttt{c:/system.old.ini} & \texttt{/.ini\$/.old.ini/} & \$ matches end of name\\ 717\hline 718\texttt{/prod/u01/pdata/} & \texttt{/rect/u01/rdata} & \texttt{/prod/rect/,/pdata/rdata/} & uses two regexp\\ 719\hline 720\texttt{/prod/u01/pdata/} & \texttt{/rect/u01/rdata} & \texttt{!/prod/!/rect/!,/pdata/rdata/} & use \texttt{!} as separator\\ 721\hline 722\texttt{C:/WINNT} & \texttt{d:/WINNT} & \texttt{/c:/d:/i} & case insensitive pattern match \\ 723\hline 724 725\end{tabular} 726 727%\subsubsection{Using group} 728% 729%Like with Perl or Sed, you can make submatch with \texttt{()}, 730% 731%\subsubsection*{Examples} 732 733 734%\subsubsection{Options} 735% 736% i Do case-insensitive pattern matching. 737 738\section{Restoring Directory Attributes} 739\index[general]{Attributes!Restoring Directory } 740\index[general]{Restoring Directory Attributes } 741 742Depending how you do the restore, you may or may not get the directory entries 743back to their original state. Here are a few of the problems you can 744encounter, and for same machine restores, how to avoid them. 745 746\begin{itemize} 747\item You backed up on one machine and are restoring to another that is 748 either a different OS or doesn't have the same users/groups defined. Bacula 749 does the best it can in these situations. Note, Bacula has saved the 750 user/groups in numeric form, which means on a different machine, they 751 may map to different user/group names. 752 753\item You are restoring into a directory that is already created and has 754 file creation restrictions. Bacula tries to reset everything but 755 without walking up the full chain of directories and modifying them all 756 during the restore, which Bacula does and will not do, getting 757 permissions back correctly in this situation depends to a large extent 758 on your OS. 759 760\item You are doing a recursive restore of a directory tree. In this case 761 Bacula will restore a file before restoring the file's parent directory 762 entry. In the process of restoring the file Bacula will create the 763 parent directory with open permissions and ownership of the file being 764 restored. Then when Bacula tries to restore the parent directory Bacula 765 sees that it already exists (Similar to the previous situation). If you 766 had set the Restore job's "Replace" property to "never" then Bacula will 767 not change the directory's permissions and ownerships to match what it 768 backed up, you should also notice that the actual number of files 769 restored is less then the expected number. If you had set the Restore 770 job's "Replace" property to "always" then Bacula will change the 771 Directory's ownership and permissions to match what it backed up, also 772 the actual number of files restored should be equal to the expected 773 number. 774 775\item You selected one or more files in a directory, but did not select the 776 directory entry to be restored. In that case, if the directory is not 777 on disk Bacula simply creates the directory with some default attributes 778 which may not be the same as the original. If you do not select a 779 directory and all its contents to be restored, you can still select 780 items within the directory to be restored by individually marking those 781 files, but in that case, you should individually use the "markdir" 782 command to select all higher level directory entries (one at a time) to 783 be restored if you want the directory entries properly restored. 784 785\item The {\bf bextract} program does not restore access control lists 786 (ACLs) to Unix machines. 787\end{itemize} 788 789\label{Windows} 790\section{Restoring on Windows} 791\index[general]{Restoring on Windows } 792\index[general]{Windows!Restoring on } 793 794If you are restoring on WinNT/2K/XP systems, Bacula will restore the files 795with the original ownerships and permissions as would be expected. This is 796also true if you are restoring those files to an alternate directory (using 797the Where option in restore). However, if the alternate directory does not 798already exist, the Bacula File daemon (Client) will try to create it. In 799some cases, it may not create the directories, and if it does since the 800File daemon runs under the SYSTEM account, the directory will be created 801with SYSTEM ownership and permissions. In this case, you may have problems 802accessing the newly restored files. 803 804To avoid this problem, you should create any alternate directory before 805doing the restore. Bacula will not change the ownership and permissions of 806the directory if it is already created as long as it is not one of the 807directories being restored (i.e. written to tape). 808 809The default restore location is {\bf /tmp/bacula-restores/} and if you are 810restoring from drive {\bf E:}, the default will be 811{\bf /tmp/bacula-restores/e/}, so you should ensure that this directory 812exists before doing the restore, or use the {\bf mod} option to 813select a different {\bf where} directory that does exist. 814 815Some users have experienced problems restoring files that participate in 816the Active Directory. They also report that changing the userid under which 817Bacula (bacula-fd.exe) runs, from SYSTEM to a Domain Admin userid, resolves 818the problem. 819 820 821\section{Restoring Files Can Be Slow} 822\index[general]{Slow!Restoring Files Can Be } 823\index[general]{Restoring Files Can Be Slow } 824 825Restoring files is generally {\bf much} slower than backing them up for several 826reasons. The first is that during a backup the tape is normally already 827positioned and Bacula only needs to write. On the other hand, because restoring 828files is done so rarely, Bacula keeps only the start file and block on the 829tape for the whole job rather than on a file by file basis which would use 830quite a lot of space in the catalog. 831 832Bacula will forward space to the correct file mark on the tape for the Job, 833then forward space to the correct block, and finally sequentially read each 834record until it gets to the correct one(s) for the file or files you want to 835restore. Once the desired files are restored, Bacula will stop reading the 836tape. 837 838Finally, instead of just reading a file for backup, during the restore, Bacula 839must create the file, and the operating system must allocate disk space for 840the file as Bacula is restoring it. 841 842For all the above reasons the restore process is generally much slower than 843backing up (sometimes it takes three times as long). 844 845\section{Problems Restoring Files} 846\index[general]{Files!Problems Restoring } 847\index[general]{Problems Restoring Files } 848 849The most frequent problems users have restoring files are error messages such 850as: 851 852\footnotesize 853\begin{verbatim} 85404-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error: 855block.c:868 Volume data error at 20:0! Short block of 512 bytes on 856device /dev/tape discarded. 857\end{verbatim} 858\normalsize 859 860or 861 862\footnotesize 863\begin{verbatim} 86404-Jan 00:33 z217-sd: RestoreFiles.2005-01-04_00.31.04 Error: 865block.c:264 Volume data error at 20:0! Wanted ID: "BB02", got ".". 866Buffer discarded. 867\end{verbatim} 868\normalsize 869 870Both these kinds of messages indicate that you were probably running your tape 871drive in fixed block mode rather than variable block mode. Fixed block mode 872will work with any program that reads tapes sequentially such as tar, but 873Bacula repositions the tape on a block basis when restoring files because this 874will speed up the restore by orders of magnitude when only a few files are being 875restored. There are several ways that you can attempt to recover from this 876unfortunate situation. 877 878Try the following things, each separately, and reset your Device resource to 879what it is now after each individual test: 880 881\begin{enumerate} 882\item Set "Block Positioning = no" in your Device resource and try the 883 restore. This is a new directive and untested. 884 885\item Set "Minimum Block Size = 512" and "Maximum Block Size = 512" and 886 try the restore. If you are able to determine the block size your drive 887 was previously using, you should try that size if 512 does not work. 888 This is a really horrible solution, and it is not at all recommended 889 to continue backing up your data without correcting this condition. 890 Please see the Tape Testing chapter for more on this. 891 892\item Try editing the restore.bsr file at the Run xxx yes/mod/no prompt 893 before starting the restore job and remove all the VolBlock statements. 894 These are what causes Bacula to reposition the tape, and where problems 895 occur if you have a fixed block size set for your drive. The VolFile 896 commands also cause repositioning, but this will work regardless of the 897 block size. 898 899\item Use bextract to extract the files you want -- it reads the Volume 900 sequentially if you use the include list feature, or if you use a .bsr 901 file, but remove all the VolBlock statements after the .bsr file is 902 created (at the Run yes/mod/no) prompt but before you start the restore. 903\end{enumerate} 904 905\section{Restore Errors} 906\index[general]{Errors!Restore} 907\index[general]{Restore Errors} 908 909There are a number of reasons why there may be restore errors or 910warning messages. Some of the more common ones are: 911 912\begin{description} 913 914\item [file count mismatch] 915 This can occur for the following reasons: 916 \begin{itemize} 917 \item You requested Bacula not to overwrite existing or newer 918 files. 919 \item A Bacula miscount of files/directories. This is an 920 on-going problem due to the complications of directories, 921 soft/hard link, and such. Simply check that all the files you 922 wanted were actually restored. 923 \end{itemize} 924 925\item [file size error] 926 When Bacula restores files, it checks that the size of the 927 restored file is the same as the file status data it saved 928 when starting the backup of the file. If the sizes do not 929 agree, Bacula will print an error message. This size mismatch 930 most often occurs because the file was being written as Bacula 931 backed up the file. In this case, the size that Bacula 932 restored will be greater than the status size. This often 933 happens with log files. 934 935 If the restored size is smaller, then you should be concerned 936 about a possible tape error and check the Bacula output as 937 well as your system logs. 938\end{description} 939 940 941 942\section{Example Restore Job Resource} 943\index[general]{Example Restore Job Resource } 944\index[general]{Resource!Example Restore Job } 945 946\footnotesize 947\begin{verbatim} 948Job { 949 Name = "RestoreFiles" 950 Type = Restore 951 Client = Any-client 952 FileSet = "Any-FileSet" 953 Storage = Any-storage 954 Where = /tmp/bacula-restores 955 Messages = Standard 956 Pool = Default 957} 958\end{verbatim} 959\normalsize 960 961If {\bf Where} is not specified, the default location for restoring files will 962be their original locations. 963\label{Selection} 964 965\section{File Selection Commands} 966\index[general]{Commands!File Selection } 967\index[general]{File Selection Commands } 968 969After you have selected the Jobs to be restored and Bacula has created the 970in-memory directory tree, you will enter file selection mode as indicated by 971the dollar sign ({\bf \$}) prompt. While in this mode, you may use the 972commands listed above. The basic idea is to move up and down the in memory 973directory structure with the {\bf cd} command much as you normally do on the 974system. Once you are in a directory, you may select the files that you want 975restored. As a default no files are marked to be restored. If you wish to 976start with all files, simply enter: {\bf cd /} and {\bf mark *}. Otherwise 977proceed to select the files you wish to restore by marking them with the {\bf 978mark} command. The available commands are: 979 980\begin{description} 981 982\item [cd] 983 The {\bf cd} command changes the current directory to the argument specified. 984 It operates much like the Unix {\bf cd} command. Wildcard specifications are 985 not permitted. 986 987 Note, on Windows systems, the various drives (c:, d:, ...) are treated like a 988 directory within the file tree while in the file selection mode. As a 989 consequence, you must do a {\bf cd c:} or possibly in some cases a {\bf cd 990 C:} (note upper case) to get down to the first directory. 991 992\item [dir] 993 \index[dir]{dir } 994 The {\bf dir} command is similar to the {\bf ls} command, except that it 995 prints it in long format (all details). This command can be a bit slower 996 than the {\bf ls} command because it must access the catalog database for 997 the detailed information for each file. 998 999\item [estimate] 1000 \index[dir]{estimate } 1001 The {\bf estimate} command prints a summary of the total files in the tree, 1002 how many are marked to be restored, and an estimate of the number of bytes 1003 to be restored. This can be useful if you are short on disk space on the 1004 machine where the files will be restored. 1005 1006\item [find] 1007 \index[dir]{find} 1008 The {\bf find} command accepts one or more arguments and displays all files 1009 in the tree that match that argument. The argument may have wildcards. It is 1010 somewhat similar to the Unix command {\bf find / -name arg}. 1011 1012\item [ls] 1013 The {\bf ls} command produces a listing of all the files contained in the 1014 current directory much like the Unix {\bf ls} command. You may specify an 1015 argument containing wildcards, in which case only those files will be 1016 listed. 1017 1018 Any file that is marked to be restored will have its name preceded by an 1019 asterisk ({\bf *}). Directory names will be terminated with a forward slash 1020 ({\bf /}) to distinguish them from filenames. 1021 1022\item [lsmark] 1023 \index[fd]{lsmark} 1024 The {\bf lsmark} command is the same as the {\bf ls} except that it will 1025 print only those files marked for extraction. The other distinction is that 1026 it will recursively descend into any directory selected. 1027 1028\item [mark] 1029 \index[dir]{mark} 1030 The {\bf mark} command allows you to mark files to be restored. It takes a 1031 single argument which is the filename or directory name in the current 1032 directory to be marked for extraction. The argument may be a wildcard 1033 specification, in which case all files that match in the current directory 1034 are marked to be restored. If the argument matches a directory rather than a 1035 file, then the directory and all the files contained in that directory 1036 (recursively) are marked to be restored. Any marked file will have its name 1037 preceded with an asterisk ({\bf *}) in the output produced by the {\bf ls} 1038or 1039 {\bf dir} commands. Note, supplying a full path on the mark command does not 1040 work as expected to select a file or directory in the current directory. 1041 Also, the {\bf mark} command works on the current and lower directories but 1042 does not touch higher level directories. 1043 1044 After executing the {\bf mark} command, it will print a brief summary: 1045 1046\footnotesize 1047\begin{verbatim} 1048 No files marked. 1049 1050\end{verbatim} 1051\normalsize 1052 1053 If no files were marked, or: 1054 1055\footnotesize 1056\begin{verbatim} 1057 nn files marked. 1058 1059\end{verbatim} 1060\normalsize 1061 1062 if some files are marked. 1063 1064\item [unmark] 1065 \index[dir]{unmark } 1066 The {\bf unmark} is identical to the {\bf mark} command, except that it 1067 unmarks the specified file or files so that they will not be restored. Note: 1068 the {\bf unmark} command works from the current directory, so it does not 1069 unmark any files at a higher level. First do a {\bf cd /} before the {\bf 1070 unmark *} command if you want to unmark everything. 1071 1072\item [pwd] 1073 \index[dir]{pwd } 1074 The {\bf pwd} command prints the current working directory. It accepts no 1075 arguments. 1076 1077\item [count] 1078 \index[dir]{count } 1079 The {\bf count} command prints the total files in the directory tree and the 1080 number of files marked to be restored. 1081 1082\item [done] 1083 \index[dir]{done } 1084 This command terminates file selection mode. 1085 1086\item [exit] 1087 \index[fd]{exit } 1088 This command terminates file selection mode (the same as done). 1089 1090\item [quit] 1091 \index[fd]{quit } 1092 This command terminates the file selection and does not run the restore 1093job. 1094 1095 1096\item [help] 1097 \index[fd]{help } 1098 This command prints a summary of the commands available. 1099 1100\item [?] 1101 This command is the same as the {\bf help} command. 1102\end{description} 1103 1104\label{database_restore} 1105\section{Restoring When Things Go Wrong} 1106\index[general]{Restoring When Things Go Wrong } 1107\index[general]{Restoring Your Database} 1108\index[general]{Database!Restoring} 1109 1110This and the following sections will try to present a few of the kinds of 1111problems that can come up making restoring more difficult. We will try to 1112provide a few ideas how to get out of these problem situations. 1113In addition to what is presented here, there is more specific information 1114on restoring a \ilink{Client}{restore_client} and your 1115\ilink{Server}{restore_server} in the \ilink{Disaster Recovery Using 1116Bacula}{RescueChapter} chapter of this manual. 1117 1118\begin{description} 1119\item[Problem] 1120 My database is broken. 1121\item[Solution] 1122 For SQLite, use the vacuum command to try to fix the database. For either 1123 MySQL or PostgreSQL, see the vendor's documentation. They have specific tools 1124 that check and repair databases, see the \ilink{database 1125 repair}{DatabaseRepair} sections of this manual for links to vendor 1126 information. 1127 1128 Assuming the above does not resolve the problem, you will need to restore 1129 or rebuild your catalog. Note, if it is a matter of some 1130 inconsistencies in the Bacula tables rather than a broken database, then 1131 running \ilink{dbcheck}{dbcheck} might help, but you will need to ensure 1132 that your database indexes are properly setup. Please see 1133 the \ilink{Database Performance Issues}{DatabasePerformance} sections 1134 of this manual for more details. 1135 1136\item[Problem] 1137 How do I restore my catalog? 1138\item[Solution with a Catalog backup] 1139 If you have backed up your database nightly (as you should) and you 1140 have made a bootstrap file, you can immediately load back your 1141 database (or the ASCII SQL output). Make a copy of your current 1142 database, then re-initialize it, by running the following scripts: 1143\begin{verbatim} 1144 ./drop_bacula_tables 1145 ./make_bacula_tables 1146\end{verbatim} 1147 After re-initializing the database, you should be able to run 1148 Bacula. If you now try to use the restore command, it will not 1149 work because the database will be empty. However, you can manually 1150 run a restore job and specify your bootstrap file. You do so 1151 by entering the {bf run} command in the console and selecting the 1152 restore job. If you are using the default bacula-dir.conf, this 1153 Job will be named {\bf RestoreFiles}. Most likely it will prompt 1154 you with something such as: 1155 1156\footnotesize 1157\begin{verbatim} 1158Run Restore job 1159JobName: RestoreFiles 1160Bootstrap: /home/kern/bacula/working/restore.bsr 1161Where: /tmp/bacula-restores 1162Replace: always 1163FileSet: Full Set 1164Client: rufus-fd 1165Storage: File 1166When: 2005-07-10 17:33:40 1167Catalog: MyCatalog 1168Priority: 10 1169OK to run? (yes/mod/no): 1170\end{verbatim} 1171\normalsize 1172 1173 A number of the items will be different in your case. What you want to 1174 do is: to use the mod option to change the Bootstrap to point to your 1175 saved bootstrap file; and to make sure all the other items such as 1176 Client, Storage, Catalog, and Where are correct. The FileSet is not 1177 used when you specify a bootstrap file. Once you have set all the 1178 correct values, run the Job and it will restore the backup of your 1179 database, which is most likely an ASCII dump. 1180 1181 You will then need to follow the instructions for your 1182 database type to recreate the database from the ASCII backup file. 1183 See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of 1184 this manual for examples of the command needed to restore a 1185 database from an ASCII dump (they are shown in the Compacting Your 1186 XXX Database sections). 1187 1188 Also, please note that after you restore your database from an ASCII 1189 backup, you do NOT want to do a {\bf make\_bacula\_tables} command, or 1190 you will probably erase your newly restored database tables. 1191 1192 1193\item[Solution with a Job listing] 1194 If you did save your database but did not make a bootstrap file, then 1195 recovering the database is more difficult. You will probably need to 1196 use bextract to extract the backup copy. First you should locate the 1197 listing of the job report from the last catalog backup. It has 1198 important information that will allow you to quickly find your database 1199 file. For example, in the job report for the CatalogBackup shown below, 1200 the critical items are the Volume name(s), the Volume Session Id and the 1201 Volume Session Time. If you know those, you can easily restore your 1202 Catalog. 1203 1204\footnotesize 1205\begin{verbatim} 120622-Apr 10:22 HeadMan: Start Backup JobId 7510, 1207Job=CatalogBackup.2005-04-22_01.10.0 120822-Apr 10:23 HeadMan: Bacula 1.37.14 (21Apr05): 22-Apr-2005 10:23:06 1209 JobId: 7510 1210 Job: CatalogBackup.2005-04-22_01.10.00 1211 Backup Level: Full 1212 Client: Polymatou 1213 FileSet: "CatalogFile" 2003-04-10 01:24:01 1214 Pool: "Default" 1215 Storage: "DLTDrive" 1216 Start time: 22-Apr-2005 10:21:00 1217 End time: 22-Apr-2005 10:23:06 1218 FD Files Written: 1 1219 SD Files Written: 1 1220 FD Bytes Written: 210,739,395 1221 SD Bytes Written: 210,739,521 1222 Rate: 1672.5 KB/s 1223 Software Compression: None 1224 Volume name(s): DLT-22Apr05 1225 Volume Session Id: 11 1226 Volume Session Time: 1114075126 1227 Last Volume Bytes: 1,428,240,465 1228 Non-fatal FD errors: 0 1229 SD Errors: 0 1230 FD termination status: OK 1231 SD termination status: OK 1232 Termination: Backup OK 1233\end{verbatim} 1234\normalsize 1235 1236 From the above information, you can manually create a bootstrap file, 1237 and then follow the instructions given above for restoring your database. 1238 A reconstructed bootstrap file for the above backup Job would look 1239 like the following: 1240 1241\footnotesize 1242\begin{verbatim} 1243Volume="DLT-22Apr05" 1244VolSessionId=11 1245VolSessionTime=1114075126 1246FileIndex=1-1 1247\end{verbatim} 1248\normalsize 1249 1250 Where we have inserted the Volume name, Volume Session Id, and Volume 1251 Session Time that correspond to the values in the job report. We've also 1252 used a FileIndex of one, which will always be the case providing that 1253 there was only one file backed up in the job. 1254 1255 The disadvantage of this bootstrap file compared to what is created when 1256 you ask for one to be written, is that there is no File and Block 1257 specified, so the restore code must search all data in the Volume to find 1258 the requested file. A fully specified bootstrap file would have the File 1259 and Blocks specified as follows: 1260 1261\footnotesize 1262\begin{verbatim} 1263Volume="DLT-22Apr05" 1264VolSessionId=11 1265VolSessionTime=1114075126 1266VolFile=118-118 1267VolBlock=0-4053 1268FileIndex=1-1 1269\end{verbatim} 1270\normalsize 1271 1272 Once you have restored the ASCII dump of the database, 1273 you will then to follow the instructions for your 1274 database type to recreate the database from the ASCII backup file. 1275 See the \ilink {Catalog Maintenance}{CatMaintenanceChapter} chapter of 1276 this manual for examples of the command needed to restore a 1277 database from an ASCII dump (they are shown in the Compacting Your 1278 XXX Database sections). 1279 1280 Also, please note that after you restore your database from an ASCII 1281 backup, you do NOT want to do a {\bf make\_bacula\_tables} command, or 1282 you will probably erase your newly restored database tables. 1283 1284\item [Solution without a Job Listing] 1285 If you do not have a job listing, then it is a bit more difficult. 1286 Either you use the \ilink{bscan}{bscan} program to scan the contents 1287 of your tape into a database, which can be very time consuming 1288 depending on the size of the tape, or you can use the \ilink{bls}{bls} 1289 program to list everything on the tape, and reconstruct a bootstrap 1290 file from the bls listing for the file or files you want following 1291 the instructions given above. 1292 1293 There is a specific example of how to use {\bf bls} below. 1294 1295\item [Problem] 1296 I try to restore the last known good full backup by specifying 1297 item 3 on the restore menu then the JobId to restore. Bacula 1298 then reports: 1299 1300\footnotesize 1301\begin{verbatim} 1302 1 Job 0 Files 1303\end{verbatim} 1304\normalsize 1305 and restores nothing. 1306 1307\item[Solution] 1308 Most likely the File records were pruned from the database either due 1309 to the File Retention period expiring or by explicitly purging the 1310 Job. By using the "llist jobid=nn" command, you can obtain all the 1311 important information about the job: 1312 1313\footnotesize 1314\begin{verbatim} 1315llist jobid=120 1316 JobId: 120 1317 Job: save.2005-12-05_18.27.33 1318 Job.Name: save 1319 PurgedFiles: 0 1320 Type: B 1321 Level: F 1322 Job.ClientId: 1 1323 Client.Name: Rufus 1324 JobStatus: T 1325 SchedTime: 2005-12-05 18:27:32 1326 StartTime: 2005-12-05 18:27:35 1327 EndTime: 2005-12-05 18:27:37 1328 JobTDate: 1133803657 1329 VolSessionId: 1 1330 VolSessionTime: 1133803624 1331 JobFiles: 236 1332 JobErrors: 0 1333 JobMissingFiles: 0 1334 Job.PoolId: 4 1335 Pool.Name: Full 1336 Job.FileSetId: 1 1337 FileSet.FileSet: BackupSet 1338\end{verbatim} 1339\normalsize 1340 1341 Then you can find the Volume(s) used by doing: 1342 1343\footnotesize 1344\begin{verbatim} 1345sql 1346select VolumeName from JobMedia,Media where JobId=1 and JobMedia.MediaId=Media.MediaId; 1347\end{verbatim} 1348\normalsize 1349 1350 Finally, you can create a bootstrap file as described in the previous 1351 problem above using this information. 1352 1353 If you are using Bacula version 1.38.0 or greater, when you select 1354 item 3 from the menu and enter the JobId, it will ask you if 1355 you would like to restore all the files in the job, and it will 1356 collect the above information and write the bootstrap file for 1357 you. 1358 1359\item [Problem] 1360 You don't have a bootstrap file, and you don't have the Job report for 1361 the backup of your database, but you did backup the database, and you 1362 know the Volume to which it was backed up. 1363 1364\item [Solution] 1365 Either bscan the tape (see below for bscanning), or better use {\bf bls} 1366 to find where it is on the tape, then use {\bf bextract} to 1367 restore the database. For example, 1368 1369 1370\footnotesize 1371\begin{verbatim} 1372./bls -j -V DLT-22Apr05 /dev/nst0 1373\end{verbatim} 1374\normalsize 1375 Might produce the following output: 1376\footnotesize 1377\begin{verbatim} 1378bls: butil.c:258 Using device: "/dev/nst0" for reading. 137921-Jul 18:34 bls: Ready to read from volume "DLT-22Apr05" on device "DLTDrive" 1380(/dev/nst0). 1381Volume Record: File:blk=0:0 SessId=11 SessTime=1114075126 JobId=0 DataLen=164 1382... 1383Begin Job Session Record: File:blk=118:0 SessId=11 SessTime=1114075126 1384JobId=7510 1385 Job=CatalogBackup.2005-04-22_01.10.0 Date=22-Apr-2005 10:21:00 Level=F Type=B 1386End Job Session Record: File:blk=118:4053 SessId=11 SessTime=1114075126 1387JobId=7510 1388 Date=22-Apr-2005 10:23:06 Level=F Type=B Files=1 Bytes=210,739,395 Errors=0 1389Status=T 1390... 139121-Jul 18:34 bls: End of Volume at file 201 on device "DLTDrive" (/dev/nst0), 1392Volume "DLT-22Apr05" 139321-Jul 18:34 bls: End of all volumes. 1394\end{verbatim} 1395\normalsize 1396 Of course, there will be many more records printed, but we have indicated 1397 the essential lines of output. From the information on the Begin Job and End 1398 Job Session Records, you can reconstruct a bootstrap file such as the one 1399 shown above. 1400 1401\item[Problem] 1402 How can I find where a file is stored. 1403\item[Solution] 1404 Normally, it is not necessary, you just use the {\bf restore} command to 1405 restore the most recently saved version (menu option 5), or a version 1406 saved before a given date (menu option 8). If you know the JobId of the 1407 job in which it was saved, you can use menu option 3 to enter that JobId. 1408 1409 If you would like to know the JobId where a file was saved, select 1410 restore menu option 2. 1411 1412 You can also use the {\bf query} command to find information such as: 1413\footnotesize 1414\begin{verbatim} 1415*query 1416Available queries: 1417 1: List up to 20 places where a File is saved regardless of the 1418directory 1419 2: List where the most recent copies of a file are saved 1420 3: List last 20 Full Backups for a Client 1421 4: List all backups for a Client after a specified time 1422 5: List all backups for a Client 1423 6: List Volume Attributes for a selected Volume 1424 7: List Volumes used by selected JobId 1425 8: List Volumes to Restore All Files 1426 9: List Pool Attributes for a selected Pool 1427 10: List total files/bytes by Job 1428 11: List total files/bytes by Volume 1429 12: List Files for a selected JobId 1430 13: List Jobs stored on a selected MediaId 1431 14: List Jobs stored for a given Volume name 1432 15: List Volumes Bacula thinks are in changer 1433 16: List Volumes likely to need replacement from age or errors 1434Choose a query (1-16): 1435\end{verbatim} 1436\normalsize 1437 1438\item[Problem] 1439 I didn't backup my database. What do I do now? 1440\item[Solution] 1441 This is probably the worst of all cases, and you will probably have 1442 to re-create your database from scratch and then bscan in all your 1443 Volumes, which is a very long, painful, and inexact process. 1444 1445There are basically three steps to take: 1446 1447\begin{enumerate} 1448\item Ensure that your SQL server is running (MySQL or PostgreSQL) 1449 and that the Bacula database (normally bacula) exists. See the 1450 \ilink{Installation}{CreateDatabase} chapter of the manual. 1451\item Ensure that the Bacula databases are created. This is also 1452 described at the above link. 1453\item Start and stop the Bacula Director using the propriate 1454 bacula-dir.conf file so that it can create the Client and 1455 Storage records which are not stored on the Volumes. Without these 1456 records, scanning is unable to connect the Job records to the proper 1457 client. 1458\end{enumerate} 1459 1460When the above is complete, you can begin bscanning your Volumes. Please 1461see the \ilink{bscan}{bscan} section of the Volume Utility Tools of this 1462chapter for more details. 1463 1464\end{description} 1465