Bacula - Backing up Hyper-V Cluster Virtual Machines (VM)

Managed ad

By justin, 7 March, 2015

Click Create.I started this series off with:

and will be continuing it with

  • Bacula SQL Backup

 

Bacula - Backing up Hyper-V Cluster Virtual Machines (VM)

Backing up in a Cluster is very similar to what we did in Bacula - Backing up Hyper-V Virtual Machines (VM), but the Powershell scripts have to look not just at 1 machine but all nodes on the cluster that have Hyper-V VMs on them.

Set each of your nodes up as discribed in Bacula Client and Windows Cluster Service and put the File Daemon as a Generic service on your Scale-Out File Service Role. Next we will have to put the scripts that are used in place. Thes scripts will go into the Bacula folder on your ClusterStorage disk whic is normally mounted in your "C:\ClusterStorage" folder and would be something like C:\ClusterStorage\Volume1.

Scripts

You will Add a couple scripts to your "C:\ClusterStorage\Volume<#>\Bacula" Directory. Those scripts can be found here. You Need to make sure you update the hightlighted paths below to reflect the location of the Powershell scripts in your ClusterStorage

There is 1 .bat file Hyper-V-Full.bat Which Kicks off the Hyper-V.Full.ps1 Powershell script and contains only 1 line:

PowerShell -ExecutionPolicy RemoteSigned -File "C:\ClusterStorage\Volume4\Hyper-V.ps1​" %1     #Update Highlighted path to the Bacula folder on your  ClusteredStorage

The system will use a variable to determine which one should be kicked off.

 

Powershell Script:

The power shell scripts that the .bat scripts kick off create snapshots on the host. this makes it easier for Bacula to backup the Hyper-V. You can update the $ClusterStoragePath in the script to backup up only VMs in a certain path.

The Hyper-V.Full.ps1 is used on Full backups. It deletes all of the Bacula-* for Full backups and Bacula-Incremental* Checkpoints (Snapshots) and creates a new one.

 

#Copyright disclaimer:
#    Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#    This program is free software: you can redistribute it and/or modify
#        it under the terms of the GNU General Public License as published by
#        the Free Software Foundation, either version 3 of the License, or
#        (at your option) any later version.
#
#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.
#
#        You should have received a copy of the GNU General Public License
#        along with this program.  If not, see <http://www.gnu.org/licenses/>.

Param(
  [string]$level

)
$DateStamp=$(((get-date)).ToString("yyyyMMddTHHmmss"))
if ($level -eq "Full"){$Backup="Bacula-*"}Else{$Backup="Bacula-$level*"}

$ClusterStoragePath="C:\ClusterStorage\volume4"  #Set your Cluster Storage path Here

#look at all nodes
$clusterNodes = Get-ClusterNode;
ForEach($item in $clusterNodes)
{
   
    write-Host "Starting Host '$($item.Name)."
    $VMs=Get-VM -ComputerName $item.Name 
        foreach ($VM in $VMs){
        
        #only get those in the Cluster Storage Path
        if ($($VM.path).ToUpper() -like ("$ClusterStoragePath\*").ToUpper()) { 
            $vm.Path
            
            write-host "Starting VM $($vm.Name) @ '$($vm.Path)'"
            $CurrentSnapShots = $VM | Get-VMSnapshot 

            #Remove old Bacula-Incrental Checkpoints (Snapshots)
            foreach ($SnapShot in $CurrentSnapShots){
                if ($SnapShot.Name -like ("$Backup")){   
                    
                    write-host "Removing VM Checkpoint '$($SnapShot.Name)'"
                    $SnapShot | Remove-VMSnapshot  
                

                    $LoopCount=0
                    do {
                        Write-host "Waiting for snapshot '$($SnapShot.name)' to delete..."
                        
                        Start-Sleep -s 10 
                        $LoopCount=$LoopCount+1
                    }while ($VM.Status -eq "Merging disks" -and $LoopCount -lt 30)
                }
            }
            

            #Create New Incremental Snapshot
            write-host "Creating Checkpoint  Bacula-$Level.$DateStamp"
            $VM | Checkpoint-VM -SnapshotName Bacula-$Level.$DateStamp
        }
    }
}

 

Creating a File Set for Windows

The biggest thing to remember is that instead of using "\" in your paths, use "/". an example is "C:\Program Files\bacula" would be "C:/Program Files/bacula". Again we will use webmin to create the File Set.

  1. Click on "File Sets"

     
  2. On the File Sets page, click "Add a new backup file set.".

     
  3.  Now you will need to fill out the form. Since the backup is not on the local machine, you have to manually type the paths to use
    1. File Name Set: Give it a name that you and others that need access to this will recognize and understand
    2. Enter the file path that that your Hyper-V machines are stored at. REMEMBER use "/" instead of "\"
    3. You will always want to exclude *.bin since these will be locked and record an error in the log if your VM is started and these files are not needed.
    4. Click "Create" Button

Create Backup Job for Hyper-V

I will assume you already have schedules and know how to create those so I will cut right to the meat and show you what you need to do to the backup job. We will do this in Webmin using the Bacula Backup Syatem:

  1. Select Backup Jobs

     
  2. Select "Add a new backup job.".

     
  3. You will need to fill in the pertinent information
    1. Backup Job Name: Give it a descriptive name
    2. Make sure the job is enabled or it will not run
    3. Default type: I usually leave this at stand-alone job
    4. Job type: Backup
    5. Backup Level: Incremental (NOTE: it will defer to the settings in the schedule to determine if it needs to do a full backup. make sure your schedule has a regular Full Backup in it.)
    6. Client to backup: Select your Hyper-V host
    7. File set to backup: Select the fileset you created in the previous section. this does not have to be only Hyper-V, you can backup other files as well.
    8. Backup on Schedule: Select the Schedule that it will use. 
    9. Destination storage device: select what to backup to. I am using a LTO-2 drive in an autochanger, but you can use any tape device or backup to file.
    10. Volume pool: select the volume pool you want it to use. I keep all backups in the Default pool, but if you want, you can break it out.
    11. Destination for messages: I keep this at Standard, but you can have the messages go where you want.
    12. Backup priority: the Default is 10, but you can set this to any positive number you want above 0. The lower the number the more important the job, so a 1 has a higher priority than a 10.
    13. Command before job (on client): this is the only command that needs to be selected for Hyper-V backups. We will us "%l" to determine if the Hyper-V-Full.bat or the Hyper-V-Incremental.bat should run. The %l is a variable that is replaced by the backup level. We also need to use the Short names generated for non-8dor3 such as C:/ClusterStorage/Volume4/Progra~1/Bacula/. It is easier just to avoid using spaces in the path for the command. You can get these by running dir /X from the command line on the windows clients. (REMEMBER: in your path use "/" instead of "\")  the command line we put in here is Change <#> to the volume number on your storage:
      C:/ClusterStorage/Volume<#>/bacula​/Hyper-V.bat​​ %l
    14. Click Create

Ok Lets test it.

  1. Click on the link in your Job:

     
  2. At the bottom of the page click "Run Now"

     
  3. Watch the magic:

Starting backup job Hyper-V ..

Automatically selected Catalog: MyCatalog Using Catalog "MyCatalog" A job name must be specified.
The defined Job resources are:
1: BackupCatalog
2: Data
3: Hyper-V
4: LocalConfig
5: Hyper-V Full Backup
6: Hyper-V Backup for Host01 Select
Job resource (1-6): 3
Run Backup job JobName: Hyper-V Level: Incremental
Client: hvcluster-fd
FileSet: Hyper-VAlwaysBackup
Pool: Default (From Job resource)
Storage: LTO-2-1 (From Job resource)
When: 2015-03-07 20:48:38 Priority: 10 OK to run? (yes/mod/no):

.. the backup job is now running. When complete, the results will be shown below ..
07-Mar 20:48 bacula-dir JobId 126: Start Backup JobId 126, Job=Hyper-V.2015-03-07_20.48.38_39
07-Mar 20:48 bacula-dir JobId 126: Using Device "LTO-2-1"
07-Mar 20:48 hvcluster-fd JobId 126: shell command: run ClientRunBeforeJob "C:/ClusterStorage/Volume4/bacula/Hyper-V-Incremental.bat" #Since it already has a current Full backup it choose to do an Incremental
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob:
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob: C:\Windows\system32>PowerShell -ExecutionPolicy RemoteSigned -File "C:\ClusterStorage\Volume4\bacula\Hyper-V.Incremental.ps1"
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting Host 'Host01. #Deleting and Creating Checkpoints on First Host
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob: C:\ClusterStorage\Volume4\Hyper-V\Backed-UP\TMG01
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting VM TMG01 @ 'C:\ClusterStorage\Volume4\Hyper-V\Backed-UP\TMG01' #Clustered VM
07-Mar 20:48 hvcluster-fd JobId 126: ClientRunBeforeJob: Removing VM Checkpoint 'Bacula-Incremental.20150307T191307' #Found an old checkpoint and is deleting it
07-Mar 20:49 hvcluster-fd JobId 126: ClientRunBeforeJob: Waiting for snapshot 'Bacula-Incremental.20150307T191307' to delete...
07-Mar 20:49 hvcluster-fd JobId 126: ClientRunBeforeJob: Creating Checkpoint Bacula-Incremental.20150307T204838 #Creating new Checkpoint for VM
07-Mar 20:50 hvcluster-fd JobId 126: ClientRunBeforeJob: C:\ClusterStorage\Volume4\Hyper-V\Backed-UP\X01 #Clustered VM
07-Mar 20:50 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting VM X01 @ 'C:\ClusterStorage\Volume4\Hyper-V\Backed-UP\X01'
07-Mar 20:50 hvcluster-fd JobId 126: ClientRunBeforeJob: Removing VM Checkpoint 'Bacula-Incremental.20150307T191307' #Found old Checkpoint
07-Mar 20:51 hvcluster-fd JobId 126: ClientRunBeforeJob: Waiting for snapshot 'Bacula-Incremental.20150307T191307' to delete...
07-Mar 20:51 hvcluster-fd JobId 126: ClientRunBeforeJob: Creating Checkpoint Bacula-Incremental.20150307T204838 #Creating New Checkpoint
07-Mar 20:52 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting Host 'Host02. #Starting Second Host
07-Mar 20:52 hvcluster-fd JobId 126: ClientRunBeforeJob: C:\ClusterStorage\volume4\hyper-v\backed-up\ts01 #Found Clustered VM
07-Mar 20:52 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting VM ts01 @ 'C:\ClusterStorage\volume4\hyper-v\backed-up\ts01'
07-Mar 20:52 hvcluster-fd JobId 126: ClientRunBeforeJob: Removing VM Checkpoint 'Bacula-Incremental.20150307T191307' #Deleting old Checkpoint
07-Mar 20:52 hvcluster-fd JobId 126: ClientRunBeforeJob: Waiting for snapshot 'Bacula-Incremental.20150307T191307' to delete...
07-Mar 20:53 hvcluster-fd JobId 126: ClientRunBeforeJob: Creating Checkpoint Bacula-Incremental.20150307T204838 #Creating New Checkpoint
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting Host 'Host03. #Starting Third Host
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: C:\ClusterStorage\volume4\hyper-v\backed-up\ap01 #Found Clustered VM
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: Starting VM AppProxy @ 'C:\ClusterStorage\volume4\hyper-v\backed-up\ap01'
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: Removing VM Checkpoint 'Bacula-Incremental.20150307T191307' #Deleting old Checkpoint
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: Waiting for snapshot 'Bacula-Incremental.20150307T191307' to delete...
07-Mar 20:54 hvcluster-fd JobId 126: ClientRunBeforeJob: Creating Checkpoint Bacula-Incremental.20150307T204838 #Creating New Checkpoint

Comments