Veeam - Wait for Running Backups to Finish

Up through version 6.x of Veeam, there is no way of copying your Veeam backups to tape, or other external media without using some other program to do this (usually a more traditional backup software like Symantec Backup Exec).

This job can be run as a "pre-run" and "post-run" job from within your backup software and will ensure you get a proper backup of your Veeam backup files by making sure that all Veeam backups have completed and stopping any new Veeam backups from starting while you're backing up the files.

Runs in two modes, Wait and Finish. In Wait mode the script will monitor Veeam and wait until all active backups have completed. When that happens it will disable the schedule for all Veeam backup jobs and exit. In Finish mode it will go through all Veeam backup jobs and re-enable the schedule.

Source Code

This script has not been checked by Spiceworks. Please understand the risks before using it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

<#
.SYNOPSIS
Simple script that runs in two modes:
1. Wait mode: will wait until all Veeam backups on your backup server
have completed, then disable all of your Veeam backup jobs.
2. Finish mode: Re-enables all Veeam backup jobs.
.DESCRIPTION
Up through version 6.x of Veeam, there is no way of copying your Veeam backups
to tape, or other external media without using some other program to do this
(usually a more traditional backup software like Symantec Backup Exec).
This job can be run as a "pre-run" and "post-run" job from within your backup
software and will ensure you get a proper backup of your Veeam backup files by
making sure that all Veeam backups have completed and stopping any new Veeam
backups from starting while you're backing up the files.
Runs in two modes, Wait and Finish. In Wait mode the script will monitor
Veeam and wait until all active backups have completed. When that happens it
will disable the schedule for all Veeam backup jobs and exit.
In Finish mode it will go through all Veeam backup jobs and enable the schedule.
** Requires Veeam Backup and Replication software with the Powershell snapin
installed.
.PARAMETER RunType
Use this parameter to tell the script which mode to run in. Accepts only
"Wait" or "Finish"
.PARAMETER WaitTime
Configurable parameter to set how long the script will wait before checking
Veeam again to make sure all Veeam backups have completed. Number value is
in seconds. Default is set to 300 seconds (5 minutes).
.EXAMPLE
.\Get-VeeamRunningJobs.ps1 -RunType Wait -WaitTime 600
Will cause the script to check Veeam backups, if backups are still running the
script will wait 10 minutes before checking again.
.EXAMPLE
.\Get-VeeamRunningJobs.ps1 -RunType Finish
Will cause the script to enable the schedule on all Veeam backup jobs.
.NOTES
Author: Martin Pugh (The Surly Admin)
Blog: www.thesurlyadmin.com
Twitter: @thesurlyadm1n
Spiceworks: Martin9700
Change Log:
1.0 Initial release
.LINK
Blog: http://thesurlyadmin.com/2012/11/08/veeam-backups-wait-for-jobs-to-finish/
Source Code: http://community.spiceworks.com/scripts/show/1678-veeam-wait-for-running-backups-to-finish
#>
Param (
[Parameter(Mandatory=$true,
HelpMessage="RunType must be either Wait or Finish")]
[ValidatePattern("Wait|Finish")]
[string]$RunType,
[int]$WaitTime = 300
)
cls
Add-PSSnapin VeeamPSSnapin -ErrorAction SilentlyContinue
If ((Get-PSSnapin "*Veeam*" -ErrorAction SilentlyContinue) -eq $null)
{ Write-Verbose "Unable to load Veeam snapin, you must run this on your Veeam backup server, and the Powershell snapin must be installed.`n`n"
Return 999
}
If ($RunType -eq "Wait")
{ #Wait for running jobs to complete
$RunningJobs = $true
Do {
If (@(Get-VBRBackupSession | Where { $_.isCompleted -eq $false }).Count -gt 0)
{ #Backups still running, time to wait...
Write-Verbose "."
Start-Sleep -Seconds $WaitTime
}
Else
{ #All Backups have completed. Disable all jobs and quit
$RunningJobs = $false
Get-VBRJob | ForEach {
$_.DisableScheduler()
}
Write-Verbose "All backup jobs have completed and have been disabled.`n`n"
}
}
While ($RunningJobs)
}
Else
{ #Reenable backup jobs
Get-VBRJob | ForEach {
$_.EnableScheduler()
}
Write-Verbose "All backup jobs have been re-enabled.`n`n"
}
Return 0