# Bacula Restores

### Useful Bacula commands

 Watch restore job:

```
watch -n1 'echo "status client client=\"srv-IP_IP_IP_IP\"" | bconsole' 
```

Check backup client status via bconsole:

```
status client
```

====================================================================================

## Bacula File Restore

\------------------------------------------------------------------------------------------------------------------------------------------------

#### 1. SSH onto backup server.

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">2. Initiate a restore</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260"> Run the following commands to initiate a restore using the backup jobID:</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Bconsole &gt; restore &gt; 3 &gt; enter Job IDs, comma seperated. </span></span>

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">3. Mark files to be restored</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Once the directory tree has been built we need to mark the /var/lib/mysql directory, and initiate the restore:</span></span>

```
mark /path/to/file
```

Run 'done' once all required files have been marked

```
done
```

Select option 9 (where):

```
9
```

Once here, you need to enter the directory we're restoring TO:

```
/root/restore_TICKETNUMBER 
```

====================================================================================

## Bacula DB Restore

[<span class="TextRun  BCX0 SCXO119910260" data-contrast="auto" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">https://kb.ukfast.net/Restore\_MySQL\_from\_Bacula</span></span>](https://kb.ukfast.net/Restore_MySQL_from_Bacula)<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260"> </span></span><span class="EOP  BCX0 SCXO119910260"> </span>

\------------------------------------------------------------------------------------------------------------------------------------------------

#### 1. SSH onto backup server.

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">2. Initiate a restore</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Run the following commands to initiate a restore using the backup jobID:</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Bconsole &gt; restore &gt; 3 &gt; enter Job IDs, comma seperated. </span></span>

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">3. Mark files to be restored</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Once the directory tree has been built we need to mark the /var/lib/mysql directory, and initiate the restore:</span></span>

```
mark /var/lib/mysql
```

Run 'done' once all required files have been marked

```
done
```

Select option 9 (where):

```
9
```

Once here, you need to enter the directory we're restoring to (on client server):

```
/root/restore_TICKETNUMBER 
```

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="EOP  BCX0 SCXO119910260"> </span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">4A. Starting 2nd MySQL Instance</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Once MySQL has been restored onto client server, we then need to start a 2</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun Superscript  BCX0 SCXO119910260" data-fontsize="8.5">nd</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260"> instance of mysql so that we can dump the required databases.</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">The below command starts the 2nd MySQL instance (You need to replace /mnt/mysql with the path we've restored MySQL to; in my example this is /root/restore\_TICKETNUMBER).</span></span>

```
/usr/sbin/mysqld --socket=/tmp/mysql2.sock --datadir=/mnt/mysql --skip-networking --pid-file=/tmp/mysql2.pid --user=mysql --skip-grant-tables
```

Running this command will take over your session, meaning that you'll have to leave this running and open a fresh SSH session.

If you're encountering errors when attempting to start the 2nd instance, it would be worth having a google of the errors. If you're still having issues, please see below:

##### 4B. Troubleshooting restore MySQL startup issues 

If you're unable to start the 2nd MySQL instance after troubleshooting, there's 2 main options:

<div class="OutlineElement Ltr  BCX0 SCXO119910260" id="bkmrk-delete-the-restored-">1. <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">Delete the restored content on the client server and start the restore again</span></span><span class="EOP  BCX0 SCXO119910260"> </span>

</div><div class="OutlineElement Ltr  BCX0 SCXO119910260" id="bkmrk-if-this-still-doesn%27">2. <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">If this still doesn't work, you can try to start the 2</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun Superscript  BCX0 SCXO119910260" data-fontsize="11">nd</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260"> MySQL instance using </span><span class="SpellingError  BCX0 SCXO119910260">innodb\_force\_recovery.</span></span><span class="EOP  BCX0 SCXO119910260">  
      
    </span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="SpellingError  BCX0 SCXO119910260">There are 6 levels of force recovery options, see [here ](https://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html)for full details.</span></span>

</div>```
/usr/sbin/mysqld --socket=/tmp/mysql2.sock --datadir=/mnt/mysql --skip-networking --pid-file=/tmp/mysql2.pid --user=mysql --skip-grant-tables --innodb_force_recovery=X
```

<span class="LineBreakBlob BlobObject DragDrop  BCX0 SCXO119910260"><span class="BCX0 SCXO119910260"> You'll need to replace 'x' on the above command with your chosen level, I'd advise starting with level 1 and moving up until the MySQL instance is started. Anything above level 4 can cause permanent data corruption, so it's ideal if we can avoid this.</span>  
</span>

<span class="LineBreakBlob BlobObject DragDrop  BCX0 SCXO119910260"><span class="BCX0 SCXO119910260">If innodb\_force\_recovery is used, please note down the level used and tell the client about this.</span></span>

<span class="LineBreakBlob BlobObject DragDrop  BCX0 SCXO119910260"><span class="BCX0 SCXO119910260"><span class="TextRun  BCX0 SCXO119910260" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">[https://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html](https://dev.mysql.com/doc/refman/8.0/en/forcing-innodb-recovery.html)</span></span><span class="EOP  BCX0 SCXO119910260"> </span></span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">If errors are being shown regarding the existing MySQL configuration,</span><span class="NormalTextRun  BCX0 SCXO119910260"> you can attempt to launch the 2nd instance with the --no-defaults flag, this essentially tells MySQL to launch with the default settings </span><span class="NormalTextRun  BCX0 SCXO119910260">:</span></span><span class="EOP  BCX0 SCXO119910260"> </span>

```
/usr/sbin/mysqld --no-defaults --socket=/tmp/mysql2.sock --datadir=/home/restore_4450884/mysql --skip-networking --pid-file=/tmp/mysql2.pid --user=mysql --skip-grant-tables 
```


\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="EOP  BCX0 SCXO119910260">5. Dumping a database</span>

<span class="EOP  BCX0 SCXO119910260">Now that we've got the restored MySQL instance running, we can look to validate the data we require is present, and dump out the database.</span>

<span class="EOP  BCX0 SCXO119910260">Connect to restored MySQL instance:</span>

```
mysql -S /tmp/mysql2.sock
```

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">Check that the required database is present:</span></span>

```
SHOW DATABASES;
```

Once we've confirmed that the databases we need is present, we can look to dump out the database into a file:

Run the following command, substituting 'databasename' with the name of your required database, and also updating 'database\_restoreTICKETNUMBER' with the appropriate ticket number.

```
mysqldump -S /tmp/mysql2.sock databasename --events --triggers --routines > /root/database_restoreTICKETNUMBER.sql
```

<div id="bkmrk-1-mysql%3E-show-databa"></div>##### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">Other options for dumping a database/s</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">All data and databases :</span></span>

```
mysqldump -S /tmp/mysql2.sock --all-databases --events --triggers --routines > /root/database_restoreTICKETNUMBER.sql
```

<div id="bkmrk-1-mysqldump--s-%2Ftmp%2F"></div><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">To dump several but not all databases (substitute databasename1,databasename2 etc) :</span></span>

```
mysqldump -S /tmp/mysql2.sock --databases databasename1 databasename2 --events --triggers --routines > /root/database_restoreTICKETNUMBER.sql
```

<div id="bkmrk-1-mysqldump--s-%2Ftmp%2F-2"></div><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">For a specific table only (substitute databasename and tablename) </span></span><span class="EOP  BCX0 SCXO119910260"> </span>

```
mysqldump -S /tmp/mysql2.sock databasename tablename > /root/database_restoreTICKETNUMBER.sql
```

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">If you're encountering errors when attempting to dump the required data, you can use the -f flag to ignore errors.</span></span>

\------------------------------------------------------------------------------------------------------------------------------------------------

#### <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun  BCX0 SCXO119910260">6. Cleaning up</span></span>

<span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">Once the dump is complete, terminate the 2</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun Superscript  BCX0 SCXO119910260" data-fontsize="8.5">nd</span></span><span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260"> instance: </span></span><span class="EOP  BCX0 SCXO119910260"> </span>

```
mysqladmin -S /tmp/mysql2.sock shutdown
```

Remove the restored /var/lib/mysql directory.

```
rm -rf /root/restore_TICKETNUMBER
```

 <span class="TextRun  BCX0 SCXO119910260" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun  BCX0 SCXO119910260">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>