Automate Bacula Restore for Testing Backups

As per my standard operating procedure, I would rather spend a week scripting something than spend one extra minute doing anything twice. Testing restores from backup jobs is something that everyone hates to do, but hopefully recognizes the criticality of such tasks, else performing backups is nearly pointless. Bacula Enterprise is a great backup/restore product (and their support is AMAZING!). Given that it is Linux based, scripting many common tasks becomes a simple concept using common Linux tools.

bconsole (the administrative interface for Bacula) commands can be automated with simple expect scripts. Below is the expect script that I created which will automate the restore of a VM to a dev ESXi host. There is another shell script executed out of cron that randomly picks a VM from the list of VM’s that have been backed up and then executes the following with an argument.

#!/usr/bin/expect -f 

set ServerToRestore [lindex $argv 0]
set timeout -1
spawn /usr/bin/bconsole

expect "\\*"
send  "restore client=10-srv-fd01 fileset=$ServerToRestore where= current select all done\r"
expect "OK to run? (yes/mod/no):"
send  "mod\r"
expect "Select parameter to modify (1-13): "
send  "13\r"
expect "Use above plugin configuration? (yes/mod/no):"
send  "mod\r"
expect "Select parameter to modify (1-7): " 
send "1\r"
expect "Please enter a value for datastore: "
send "datastore2\r"
expect "Use above plugin configuration? (yes/mod/no):"
send  "mod\r"
expect "Select parameter to modify (1-7): "
send "2\r"
expect "Please enter a value for restore_host: "
send "10-dev-vm03.domain.com\r"
expect "Use above plugin configuration? (yes/mod/no):"
send  "mod\r"
expect "Select parameter to modify (1-7): "
send "4\r"
expect "Please enter a value for vsphere_server: "
send "10-dev-vm03\r"
expect "Use above plugin configuration? (yes/mod/no): "
send "yes\r"
expect "OK to run? (yes/mod/no):"
send  "mod\r"
expect "Select parameter to modify (1-13): "
send  "7\r"
expect "Enter new Priority: "
send  "15\r"
expect "OK to run? (yes/mod/no): "
send "yes\r"
expect "\\*"
send "quit\r"
exit

Each morning someone on my team validates the restore and documents the successes and failures and, if necessary, creates a ticket to determine the cause of any such failure.

Leave a Reply

Your email address will not be published. Required fields are marked *