Quantcast
Channel: Rob V IT
Viewing all articles
Browse latest Browse all 64

Veeam backup copy to multiple offline external disks

$
0
0

Wondering how to create an offline disk back-up copy with more than one USB Disk? And not want to spend your IT budget on “Veeam cloud connect” This is originally not possible with the Veeam GUI because you can’t map 1 backup copy job against 2 USB disks. The job will fail because Veeam cant find one incremental which one is copied on the second USB disk which is on a safe place @home. I made a script for enabling and disabling the right copy job for each mapped USB disk.

<#
.SYNOPSIS
    Veeam offline copy to USB or other External disk.
 
.DESCRIPTION
    
    PRE-REQUIREMENT!!: 1 or more usb or external disks. Created repositories and Backup copy jobs in Veeam.
    This scripts contains 3 Functions
        1. Prepare offline media for copying to it.
        2. Enable and Disable Veeam jobs.
        3. Write logging to file
 
.PARAMETER(s) 
    
    $DiskId = The diskid which is given in the get partition CMDLet or gui.
    $TargetDrvLtr = Driveletter where the Veeam repository is mapped to
    $USBDisklabels = Volumenames
    $BCopyJob = Backupcopyjobnames
    $Logfile = Logging the actions to a logfile
  
.INPUTS
    $PartitionInfo = PartitionStuff -DiskId "usb" -TargetDrvLtr "Z"
	TheVeeamStuff -PartitionInfo $PartitionInfo -UsbDiskLabel1 "USBDISKLABEL1" -UsbDiskLabel2 "USBDISKLABEL2" -BCopyJob1 "BCOPY1" -BCopyJob2 "BCOPY2" -logfile "C:\PSScripts\VBRTaskLogging.txt"

 
.OUTPUTS
    Log file stored in C:\.log>
 
.NOTES
    Version:        1.0
    Author:         Rob Verhees
    Creation Date:  13-12-2018
    Purpose/Change: Initial script development
  
#>
 



Function PartitionStuff {

    Param(
        $DiskId,
        $TargetDrvLtr
    )

 
    $drvltr = get-partition | where{$_.DiskId -match $DiskId} 
    
    IF(!$drvltr){
        write-log -Level ERROR -logfile $logfile -Message "Cant find disk with DiskID $($diskid)"
    }


    IF($drvltr.DriveLetter -ne $TargetDrvLtr ){
       $drvltr | Set-Partition -NewDriveLetter $TargetDrvLtr

    } Else {
       write-log -Level INFO -logfile $logfile -Message "TargetDriveletter already present!" 

    }
    
    IF($drvltr){
        $PartitionInfo = $drvltr | get-volume | select -ExpandProperty filesystemlabel
    }

    $PartitionInfo

}


function LoadVeeamPowerShell {

    Try {
       Add-PSSnapin VeeamPSSnapin
    
    } Catch {
       write-log -Level ERROR -logfile $logfile -Message "Cant load Veeam!"
       Exit
    }

    Try {
       get-vbrserver 

    } Catch {
        
        write-log -Level ERROR -logfile $logfile -Message "Change the permissions of the following registry key: \\HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication\ -> Users full control."
        write-log -Level ERROR -logfile $logfile -Message ":: Or run this Script as Administator, not recommended when using a scheduled task."
        Exit
    }


}


function TheVeeamStuff {

    Param (
        $PartitionInfo,
        $UsbDiskLabel1,
        $UsbDiskLabel2,
        $BCopyJob1,
        $BCopyJob2,
        $logfile
    )


    LoadVeeamPowerShell

    IF($PartitionInfo -match $UsbDiskLabel1){
          
          Try {
                Get-VBRBackupRepository -Name $UsbDiskLabel1 | Sync-VBRBackupRepository
                write-log -Level INFO -logfile $logfile -Message "Syncing repository $($usbdisklabel1)"
                
                start-sleep -Seconds 60
                
                Get-VBRJob | where{$_.name -eq $BCopyJob1} | Enable-VBRJob
                write-log -Level INFO -logfile $logfile -Message ":: Enabling VBRJob $($BCopyJob1)"
                
                Get-vbrjob | where{$_.name -eq $BCopyJob2} | Disable-VBRJob
                write-log -Level INFO -logfile $logfile -Message ":: Disabling VBRJob $($BCopyJob2)"

          } Catch {
                write-log -Level ERROR -logfile $logfile -Message "Can't find VBRjob or Repository"
                write-log -Level ERROR -logfile $logfile -Message ": Errormessage: $($_.exception.message)"
                Exit    
          
          } 
    }

    ELSEIF($PartitionInfo -match $UsbDiskLabel2) {
           
           Try {
                Get-VBRBackupRepository -Name $UsbDiskLabel2 | Sync-VBRBackupRepository
                write-log -Level INFO -logfile $logfile -Message "Syncing repository $($usbdisklabel2)"

                start-sleep -Seconds 60

                Get-VBRJob | where{$_.name -eq $BCopyJob2} | Enable-VBRJob
                write-log -Level INFO -logfile $logfile -Message ":: Enabling VBRJob $($BCopyJob2)"
                
                Get-vbrjob | where{$_.name -eq $BCopyJob1} | Disable-VBRJob
                write-log -Level INFO -logfile $logfile -Message ":: Disabling VBRJob $($BCopyJob1)"
           
           } Catch {
               write-log -Level ERROR -logfile $logfile -Message "Can't find VBRjob or Repository"
               write-log -Level ERROR -logfile $logfile -Message ": Errormessage: $($_.exception.message)"  

           }
           }

    Else {
        write-log -Level ERROR -logfile $logfile -Message "$($Partitioninfo) and the given External disk label does not match each-other."

    }

}


Function Write-Log {
    
    [CmdletBinding()]
    
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")]
        [String]
        $Level = "INFO",
 
        [Parameter(Mandatory=$True)]
        [string]
        $Message,
 
       [Parameter(Mandatory=$False)]
       [string]
        $logfile
    )
 
    $Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
    $Line = "$Stamp $Level $Message"
    
    If($logfile) {
        if (!(Test-Path $logfile))
        {
            New-Item -path $logfile -type "file"
            
        }

        Add-Content $logfile -Value $Line
    
    }
    
    Else {
    
        Write-Output $Line
    
    }
}


$PartitionInfo = PartitionStuff -DiskId "usb" -TargetDrvLtr "Z"
TheVeeamStuff -PartitionInfo $PartitionInfo -UsbDiskLabel1 "USBDISKLABEL1" -UsbDiskLabel2 "USBDISKLABEL2" -BCopyJob1 "BCOPY1" -BCopyJob2 "BCOPY2" -logfile "C:\PSScripts\VBRTaskLogging.txt"

 

The post Veeam backup copy to multiple offline external disks appeared first on Rob V IT.


Viewing all articles
Browse latest Browse all 64

Trending Articles