That's the process that we'll follow in order to carry out a security copy:
Bacula Director Daemon(backuo01) has access to the Bacula Client Daemon in order to start a copy of virtual01.
- Bacula Client Daemon(production01) will check virtual01 status. In case it's running, it will be shutdown.
If we want to carry out a a backup of a complete machine, it must be stopped or suspended. Otherwise, date will be corrupted recovery won't probably work correctly. - Once the machine is shutdown, production01 will launch reflink in order to provide a file copy of the suspended virtual machine.
- After carrying out the copy of virtual01, production01 will be restored from its suspended status, and virtual01 will be started again.
- Once we have a copy of the virtual machine and the original one is running again, we compress the copy in order to minimize the copy transference to the backstorage and to save disk space.
- In the following step Bacula Client Daemon (production01) must communicate Bacula Storage Daemon(desarrollo01) in order to store virtual01 in backupstorage.
- Finally, if the copy has been correctly carried out, files created during this process will be deleted by reflink instruction and the compression process.
Bacula Director Daemon file, which is stored in backup01, must be configured with a new Job. A Job is a used by Bacula to define backup tasks that need to be programmed. In order to do it you need to add three more fields to this configuration file. In the following example you can see how to add the client that will perform this new task:
Code Block | ||||
---|---|---|---|---|
| ||||
Client { Name = produccion01-fd Address = produccion01 # IP FDPort = 9102 Catalog = MyCatalog Password = "produccion01-fd.password" File Retention = 1 year Job Retention = 1 year AutoPrune = yes Maximum Concurrent Jobs = 10 } |
Now, you must define where the client will store the security copy:
Code Block | ||||
---|---|---|---|---|
| ||||
Storage { Name = storage_virtual01_full" Address = desarrollo01 SDPort = 9103 Password = "desarrollo01-sd.password" Device = backup_erp01_full Maximum Concurrent Jobs = 10 Media Type = file_virtual01_full" } |
Code Block | ||||
---|---|---|---|---|
| ||||
Schedule { Name = "schedule_virtual01_full" Run = Level=Full Pool=pool_mensual on 1,16 at 3:00 Run = Level=Full Pool=pool_quincenal sun-sat at 3:00 } FileSet { Name = "fileset_virtual01_full" Include { Options { signature = SHA1; onefs = yes; } File = /storage/virtual01-bk.tar.gz } } Job { Name = "job_virtual01_full" Type = Backup Level = Full Client = produccion01-fd FileSet = "fileset_virtual01_full" Schedule = "schedule_virtual01_full" Storage = storage_virtual01_full" Messages = Standard Pool = pool_anual Full Backup Pool = pool_mensual Incremental Backup Pool = pool_quincenal Priority = 11 Write Bootstrap = "/apps/bacula/opt/bacula/working/virtual01_full.bsr" ## Script running on client Client Run Before Job = "/bacula/script/vm_stop.sh virtual01" Client Run After Job = "/bacula/script/vm_start.sh virtual01" } |
Code Block | ||||
---|---|---|---|---|
| ||||
File = /storage/virtual01-bk.tar.gz |
Code Block | ||||
---|---|---|---|---|
| ||||
Client Run Before Job = "/apps/bacula/script/vm_stop.sh virtual01" Client Run After Job = "/apps/bacula/script/vm_start.sh virtual01" |
If you want to know with more detail the rest of settings that have be configured, you can visit the Bacula documentation (www.bacula.org).
once you have defined the Jobe in Bacula Director Daemon, we need to create the Device (location where the security copy for virtual01 will be stored) in Bacula Storage Daemon (development01). In order to do this, we must edit the configuration file (.../bacula/etc/bacula-sd.conf) and add the following lines.
Code Block | ||||
---|---|---|---|---|
| ||||
Device { Name = backup_virtual01_full Media Type = file_erp01_sql Archive Device = /backup/vm/virtual01 LabelMedia = yes; Random Access = Yes; AutomaticMount = yes; RemovableMedia = no; AlwaysOpen = no; Maximum Concurrent Jobs = 10 } |
Finally, we need to define two scripts:
- the first one will stop the virtual machine in order to do the copy and restoration
- the second one will delete the security copy already copied in storagebackup.
Both scripts must be located in production01 (Bacula Client Daemon)
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
##/bin/bash PASS=`cat /root/pass` MACHINE=$1 LOGFILE=/bacula/log/log_$MACHINE.log DATE=`date +%d%m%Y` echo " " >> $LOGFILE echo "-------------------------------" $MACHINE "--" `date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` "---------------------------------------" >> $LOGFILE ESTADO=`flexadm guest-status -p $PASS -g $MACHINE` if [ $ESTADO = "running" ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE esta en ejecucion, se suspende..." >> $LOGFILE flexadm -p $PASS -g $MACHINE suspend -w sleep 300 ESTADO=`flexadm guest-status -p $PASS -g $MACHINE` if [ $ESTADO = "running" ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE No se ha suspendido después de 5 minutos se suspende la copia." >> $LOGFILE flexadm -p $PASS -g $1 restore -w #Asegurar que la maquina queda en ejecucion elif [ $ESTADO = "suspended" ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE se ha suspendido, se crea backup ($MACHINE-bk)." >> $LOGFILE LUGAR=`flexadm -p $PASS -g $1 guest-images` reflink $LUGAR $LUGAR-bk if [ $? -eq 0 ] then if [ -f $LUGAR-bk ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk creado, se comprime ($MACHINE-bk_$DATE.tar.gz)." >> $LOGFILE fi tar -cf $LUGAR-bk_$DATE.tar.gz $LUGAR-bk if [ $? -eq 0 ] then if [ -f $LUGAR-bk_$DATE.tar.gz ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk comprimida ($MACHINE-bk_$DATE.tar.gz), se borra $MACHINE-bk." >> $LOGFILE rm -rf $LUGAR-bk if [ $? -eq 0 ] then if [ ! -f $LUGAR-bk ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk borrada." >> $LOGFILE echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` Backup de $MACHINE creado correctamente." >> $LOGFILE fi else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` ERROR AL BORRAR $MACHINE-bk" >> $LOGFILE fi fi else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` ERROR AL COMPRIMIR $MACHINE-bk NO SE HA CREADO ($MACHINE-bk_$DATE.tar.gz)" >> $LOGFILE fi else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` ERROR AL CREAR $MACHINE-bk" >> $LOGFILE fi fi elif [ $ESTADO = "suspended" ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE suspendida" >> $LOGFILE fi echo "--------------------------------------------------------------------------------------------------------" >> $LOGFILE |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/bash PASS=`cat /root/pass` MACHINE=$1 LOGFILE=/bacula/log/log_$MACHINE.log DATE=`date +%d%m%Y` echo " " >> $LOGFILE echo "-------------------------------" $MACHINE "--" `date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` "---------------------------------------" >> $LOGFILE ESTADO=`flexadm guest-status -p $PASS -g $MACHINE` if [ $ESTADO = "running" ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE esta restaurada" >> $LOGFILE LUGAR=`flexadm -p $PASS -g $MACHINE guest-images` if [ -f $LUGAR-bk.tar.gz ] then rm -rf $LUGAR-bk.tar.gz if [ $? -eq 0 ] then if [ ! -f $LUGAR-bk.tar.gz ] then echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk.tar.gz borrado con exito" >> $LOGFILE else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk.tar.gz no se ha borrado" >> $LOGFILE fi else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` ERROR AL BORRAR $MACHINE-bk.tar.gz" >> $LOGFILE fi else echo "`date +%d`-`date +%m`-`date +%Y` `date +%H`:`date +%M` $MACHINE-bk.tar.gz no existe" >> $LOGFILE fi fi echo "--------------------------------------------------------------------------------------------------------" >> $LOGFILE |