I have a Windows Server 2016 server with a number of Hyper-V virtual machines running on it, and Windows Server Backup wasn’t backing them up for reasons known only to Microsoft. Various forums and reports on Microsoft’s Technet suggest there’s a fix needed for Server 2016 which, two years after first complaints, still hasn’t been forthcoming. Everywhere seemed to suggest using something like Veeam Backup & Replication instead, so I installed that.
I only need a simple “backup the VM periodically” function, and Veeam B&R has this option in the free version in the form of VeeamZIP. This is all well and good, but it’s ad-hoc backup only – no scheduling unless you fork out for the paid versions. Luckily, Veeam themselves have a PowerShell script that you can schedule, which makes use of the Start-VBRZip command.
Sadly, it wouldn’t work for me, and it turns out it’s because I’m backing up to a Synology NAS.
If you look at the script, you’ll see this:
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup) $Directory = ""
If I set $Directory to a location local to the server (e.g. “d:\”) then it works. Set it to the NAS (e.g. “\\synonas\share\backups”) and I get the error “Failed to process [isFileExists]”.
Looking on the NAS, the logs say the server connected – with working credentials – but no files are created. After the usual head-scratching and log searching, I realised something: The script is running with the correct credentials, but the Start-VBRZip command in it is not.
On the PowerShell command line itself, you can specify which credentials Start-VBRZip can use with the -NetworkCredentials parameter. You can read more about that here. However, there are two steps needed to get that working:
- Create a set of stored credentials in the Veeam Backup & Replication GUI, using the “Manage Credentials” option.
- Retrieve that in the form of an array in PowerShell and pass it to Start-VBRZip.
The second step is necessary because the parameter expects an array not a string. If you have a set of credentials for (e.g.) “DOMAIN\Admin” stored in Veeam B&R, you can’t just pass -NetworkCredentials “DOMAIN\Admin”.
What you can do, however, is extract the array necessary with this command:
$cred = Get-VBRCredentials -Name "DOMAIN\Admin"
and then pass $cred to Start-VBRZip’s -NetworkCredentials parameter.
Only there’s another snag: the provided PowerShell script doesn’t do anything with credentials as the parameter is missing. We can fix that by adding it ourselves.
In the script, there’s a line that says “DO NOT MODIFY PAST THIS LINE”. To hell with that! Immediately after the “Ansp VeeamPSSnapin” line, add
$cred = Get-VBRCredentials -Name "DOMAIN\Admin"
then rewrite these lines:
If ($EnableEncryption) { $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString) $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey } Else { $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention }
to include the missing parameter:
If ($EnableEncryption) { $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString) $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey -NetworkCredentials $cred } Else { $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -NetworkCredentials $cred }
Save the file, add it to Task Scheduler as per the Veeam instructions, and it should now work!
Thanks! This worked perfectly.
Thank you for posting this. I had the same error with Veeam Free saving to shared NAS location and adding credentials has fixed the issue 🙂