PowerShell script exchange
j.h.needed
Novice
Posts: 3
Liked: never
Joined: Feb 10, 2017 10:37 am
Full Name: jason
Contact:

Retention Policy issues...

Post by j.h.needed »

Hi there,

We've recently (at last) upgraded our Veeam Backup and Restore (free version) from 9.0 to 9.5.

Since the upgrade our scheduled tasks (utilising the powershell script for scheduled backups) no longer pay attention to the retention policy - no backups are removed now.
The retention policy has been set to a combination of 'Tonight' or 'TomorrowNight' in different locations - we have the solution installed in 4 different locations. Regardless of the location - all backup instances have exhibited the same behaviour of aged backups no longer being removed.

Note: backups all run successfully with no other issues seen.

Is there something obvious that I've overlooked or need to amend as part of the update to 9.5?

Code: Select all

----------------------------------
##################################################################
#                   User Defined Variables
##################################################################

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = "server1","server2","server3"
# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "serverHVhost"
 
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "\\serverbackup\folder"

# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme)
$CompressionLevel = "9"

# Quiesce VM when taking snapshot (Optional; VMware Tools or Hyper-V Integration Components are required for this in the guest OS; Possible values: $True/$False)
$EnableQuiescence = $False

# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False

# Encryption Key (Optional; path to a secure string)
$EncryptionKey = ""

# Retention settings (Optional; by default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
# Possible values: Never, Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = "Tonight"
---------------------------------------

Thanks in advance

Jason
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Retention Policy issues...

Post by Andreas Neufert »

Can you please post the line that uses the $Retention (Start-VBRZip). Thank you.
j.h.needed
Novice
Posts: 3
Liked: never
Joined: Feb 10, 2017 10:37 am
Full Name: jason
Contact:

Re: Retention Policy issues...

Post by j.h.needed »

Hi, we have:-

Code: Select all

-------------------------------
$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRHvEntity -Name $VMName -Server $Server
  
  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
  }
  
  If ($EnableNotification) 
  {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
  
  if ($FailedSessions -ne $Null)
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
  }
   
  Else
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result)
  }
  
  }   
}
------------------------------
Thank you
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Retention Policy issues...

Post by Andreas Neufert »

Looks good.
We can try to install update 1 https://www.veeam.com/kb2222
and if this will not help we need to open a ticket please.
Please post the ticket number here then.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

I've tested it on 9.5 Update 1, the retention policy has worked as expected deleting created backup files the other night. Thanks.
j.h.needed
Novice
Posts: 3
Liked: never
Joined: Feb 10, 2017 10:37 am
Full Name: jason
Contact:

Re: Retention Policy issues...

Post by j.h.needed »

thanks for that link - will give this a try just now
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Jason, if the retention doesn't work, can you, please, try to reproduce the behaviour via GUI as well?

We've checked the structure of this cmdlet and connection between cmdlet wrappers and internal db calls seems to be right. So, the experienced problem may lay outside of PowerShell functionality.

Thanks.
Castillo
Lurker
Posts: 1
Liked: never
Joined: May 31, 2017 2:47 pm
Full Name: Steve Castell
Contact:

Re: Retention Policy issues...

Post by Castillo »

Hi,
I'm getting the same problem with backups not deleting after the retention period has expired.

This issue does not occur if the backup file is located on a local disk on the Veeam Server, but when the backup is located on a UNC share then it does not delete after the specified retention period.

We're running Veeam Backup and Replication 9.5 Update 2 Free Edition.

Is anyone else having this issue?
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Retention Policy issues...

Post by Andreas Neufert »

I know dump question.... Can you manually create and delete files there?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Most likely, Veeam service account lacks required permissions on a given share.
Jawloms
Lurker
Posts: 1
Liked: never
Joined: Oct 17, 2017 10:44 am
Full Name: Stuart Hawkins
Contact:

Re: Retention Policy issues...

Post by Jawloms »

j.h.needed - Did you sort this as I have just upgraded to 9.5 Update 2 and am having the same problem.

Thank you

Stuart
FreekouT
Lurker
Posts: 1
Liked: never
Joined: Jan 19, 2018 8:50 am
Contact:

Re: Retention Policy issues...

Post by FreekouT »

I figured out, that when I delete all VMs backups from target location, the retention policy set in Powershell script starts to work properly.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

By the way, in Update 2 there used to be problems with VeeamZIP retention policy not applying correctly. Those issues are addressed in Update 3; might be worth updating. Thanks.
Leutin
Novice
Posts: 3
Liked: never
Joined: Feb 05, 2018 8:05 am
Contact:

Re: Retention Policy issues...

Post by Leutin »

Hello!
I'm using free version of Veeam B&R 9.5 update 3 (9.5.0.1536), and exrepiencing issues with the retention too.
Every night I run script that backups VMs to the UNC share with the credentials previously added to the VB&R via Console:

Code: Select all

$Credentians = "credentials name as shown in the VB&R Console"
$EncryptionKeyDescription = "encryption key description as shown int the VB&R Console"
$NetCreds = Get-VBRCredentials -Name $Credentials
$ZIPSession = Start-VBRZip -Entity $VM `
                           -Folder "\\nas\backups" `
                           -Compression $CompressionLevel `
                           -DisableQuiesce:$False `
                           -AutoDelete "In1Week" `
                           -NetworkCredentials $NetCreds `
                           -EncryptionKey (Get-VBREncryptionKey -Description $EncryptionKeyDescription)
UNC share is located on the Synology NAS. Of cource, I created separete account on NAS and gave it needed permissions, then added credential to the VB&R.
Encrtyption key added via VB&R console, too.
Backups saved as well, but it does not deleted after time interval specified in the command-line.

How could I fix this issue?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Hmm, can you reproduce this via GUI? Anyway, it might be worth opening a support ticket and letting them check debug logs. Thanks.
fabio.r
Lurker
Posts: 1
Liked: never
Joined: Feb 13, 2018 9:57 am
Contact:

Re: Retention Policy issues...

Post by fabio.r »

Hello, I have the same situation of Leutin, but without encryption and retention set to In3Days, have you found a solution?
Leutin
Novice
Posts: 3
Liked: never
Joined: Feb 05, 2018 8:05 am
Contact:

Re: Retention Policy issues...

Post by Leutin »

v.Eremin wrote:Hmm, can you reproduce this via GUI?
Unfortunately, no - I use free version, and I don't know how to use autoretention feature via GUI.
Also, I met solution in the internet to give Veeam machine AD account give permissions to the UNC share used for backups.
I was unable to do it because UNC share located on the Synology NAS, so I created separate AD user, give it permissions to the share and set Veeam Data Mover Service to run with this account.
This does not solved the issue - backups still not removed automatically.
v.Eremin wrote:Anyway, it might be worth opening a support ticket and letting them check debug logs. Thanks.
I am a newbie here, so I don't know how to open a support ticket yet.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Unfortunately, no - I use free version, and I don't know how to use autoretention feature via GUI.
You can apply retention policy to VeeamZIP backup even in free edition. (delete this backup automatically setting)
Also, I met solution in the internet to give Veeam machine AD account give permissions to the UNC share used for backups.
Specify required account as credentials in the same UI wizard and see whether the issue is reproduced.

Thanks.
Leutin
Novice
Posts: 3
Liked: never
Joined: Feb 05, 2018 8:05 am
Contact:

Re: Retention Policy issues...

Post by Leutin »

OK. I made two backups of two different VMs with different autodelete settings ("Tonight" and "Tomorrow Night") via GUI, will check if it will be autodeleted.

Manual said:

Code: Select all

Veeam Backup & Replication checks the
retention policy set for the job. If some backup files in the backup chain are outdated,
Veeam Backup & Replication removes them from the backup chain.

VeeamZIP files are automatically deleted after some period of time: on the same night, the next night, in 3 days, in a week and so on.
Which process should remove old backups, and when should it be removed?
Should it be task for same machine with the same destination?
Could I have backups of the same VM in the same destination with different autoretention settings at the same time?
It's not clear in the documentation.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Which process should remove old backups, and when should it be removed?
Should be removed tonight and tomorrow night by backup server.
Should it be task for same machine with the same destination?
Unfortunately, I didn't get the question, could you elaborate?
Could I have backups of the same VM in the same destination with different autoretention settings at the same time?
Yes, you can.
Marco.S
Lurker
Posts: 2
Liked: never
Joined: Feb 28, 2018 10:50 am
Full Name: Marco Sai
Contact:

Re: Retention Policy issues...

Post by Marco.S »

Hi All,
We experience the same problems with the retention rules.
Those customers who use the licensed version of veeam 9.5 have no problems, horewer we have 2 cases where the free edition is used.
In both cases, using veeam 9.5 update 3 (one is an upgrade from 9.0 the other is a fresh install) we are able to create backups on the network share but older backup are not deleted.

I tried using the gui, creating a backup using the retention (with delete tonight option) and they are not autodeleted.
The network share is in both cases a synology nas.
I tried to set permissions to windows acl and also tried to setup the user as administrator but still no effects.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

I tried using the gui, creating a backup using the retention (with delete tonight option) and they are not autodeleted.
In this case log a ticket with our support team and let them confirm your environment. Thanks.
Marco.S
Lurker
Posts: 2
Liked: never
Joined: Feb 28, 2018 10:50 am
Full Name: Marco Sai
Contact:

Re: Retention Policy issues...

Post by Marco.S »

Hi all,

I opened a ticket and I had a remote connection with veeam support (BTW IT'S AMAZING!), the problem seems to be that the $netcreds variable only work for opeming the remote share connection.
The veeam backup service instead work using the local machine account so when it tries to delete the files it receives a "permission denied" from the remote NAS.

Support suggested that the local machine account and the remote repository share account must be the same, so I guess both devices must be under active directory and using the same account.

Horewer I can't test this since they are very small business, they don't have an avaible domain controllers.

Edit: solved the problem using synology scheduler to delete files older than I need from the repository folder

This info maybe can solve this problems for other people.
ycl
Lurker
Posts: 1
Liked: never
Joined: Feb 09, 2018 11:42 am
Contact:

Re: Retention Policy issues...

Post by ycl »

Hi all,

Got the same problem. From the log, seems it backup with the netcred provided but not deleting it with the same netcred

Code: Select all

[07.03.2018 00:00:23] <64> Info     [VeeamZIPRetention] Deleting file [\\"NASpath"\test pcD2018-03-06T171849.vbk] on repository [Local filesystem] because it's due is 7/3/2018 0:00:00 
[07.03.2018 00:00:23] <64> Info         [Local] Check existing '\\"NASpath"\test pcD2018-03-06T171849.vbk'
[07.03.2018 00:00:24] <64> Warning  [VeeamZIPRetention] Cannot delete the file [\\"NASpath"\test pcD2018-03-06T171849.vbk] on the repository [Local filesystem] because it does not exist or you have no permissions to access to this location.
We didn't mount the NAS on server, the last ransomware attack encrypted the backup because the pc had access to its backup on NAS
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

We're checking this at the moment. Will update the topic, once I have more information. Thanks.
nzorn
Influencer
Posts: 24
Liked: never
Joined: Nov 13, 2014 2:57 pm
Contact:

Re: Retention Policy issues...

Post by nzorn »

Any update on this? I believe we are also seeing this with the -NetworkCredentials switch.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

QA team believe that retention policy issues have been solved in Update 3.

If you still experience these problems, kindly, open a ticket with our support team, provide required logs and post case number here.

Thanks.
nzorn
Influencer
Posts: 24
Liked: never
Joined: Nov 13, 2014 2:57 pm
Contact:

Re: Retention Policy issues...

Post by nzorn »

Thanks, Case # 03031584
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Retention Policy issues...

Post by veremin »

Based on the provide support ticket, it seems to be permissions issue. Can you tell me whether within a script you've specified share credentials using -NetworkCredentials parameter? Thanks.
nzorn
Influencer
Posts: 24
Liked: never
Joined: Nov 13, 2014 2:57 pm
Contact:

Re: Retention Policy issues...

Post by nzorn »

My actual script is attached to the case if that helps, but I modified the https://www.veeam.com/blog/veeam-backup ... shell.html script slightly to add in the -NetworkCredentials:

$DirectoryCreds = "VEEAM"

$NetCreds = Get-VBRCredentials -Name "$DirectoryCreds"

$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey -NetworkCredentials $netcreds

$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -NetworkCredentials $netcreds



Code: Select all



# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/member31097.html
# 

##################################################################
#                   User Defined Variables
##################################################################

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = "VM1","VM2"

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "vCENTER.URL"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "\\UNC\PATH"

# Network Credentials for the directory path listed above
$DirectoryCreds = "VEEAM"

# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme) 
$CompressionLevel = "5"

# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $False

# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False

# Encryption Key (Optional; path to a secure string)
$EncryptionKey = ""

# Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time. 
# Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = "In2Weeks"

##################################################################
#                   Notification Settings
##################################################################

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = "smtp.URL"

# Email FROM
$EmailFrom = "email@address.com" 

# Email TO
$EmailTo = "email@address.com"

# Email subject
$EmailSubject = "Veeam Free Backup Report"

##################################################################
#                   Email formatting 
##################################################################

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

##################################################################
#                   End User Defined Variables
##################################################################

#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin

$NetCreds = Get-VBRCredentials -Name "$DirectoryCreds"
$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
  
  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 $netcreds
  }
  
  Else 
  {
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -NetworkCredentials $netcreds
  }
  
  If ($EnableNotification) 
  {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
  
  if ($FailedSessions -ne $Null)
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
  }
   
  Else
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
  }
  
  }   
}
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests