post-job script need to delete files that were written.

PowerShell script exchange

post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Fri Nov 13, 2015 10:40 pm

I am looking for a way to run a post job script, that will let me delete files off a drive once they have been successfully written to tape.

Do any cmdlets exist that would let me list the files written to tape for the current run of the job?
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Mon Nov 16, 2015 8:37 am

Do you want to delete backup files (.vbk, .vrb, .vib) or just ordinary files that have been just archived to tapes with the use of files to tape job?
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Thu Dec 10, 2015 5:38 pm

For some reason I never got the notification of your response.

The files to tape job in question, backs up trans log files from a network share, I need to remove them once they have been written to tape ( and are more than 3 days old, but I can script that check).
I need the file path that is backed up for each file eg: s:\folder\file.trans
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Thu Dec 10, 2015 6:12 pm

From the top of my head the script being scheduled as a post-job activity would do something like the following:

- Get a Tape Job

Code: Select all
$TapeJob = Get-VBRTapeJob -name "Name of your tape job"


- Check whether the latest job result was successful

Code: Select all
$TapeJob.LastResult -eq "Success"


- In case of positive answer get the latest job session

Code: Select all
$Session = Get-VBRSession -Job $TapeJob -Last


- Get the session log
Code: Select all
$Log = $Session.log

- Check among title entities whether all source files were backed up successfully, and none was skipped. (I don't have a files to tape job at hand, so, can't check the exact wording

- In case of positive answer delete the files in given directory (you've said that this part is not a problem for you)

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Mon Dec 14, 2015 3:42 pm

$log gives useless data.

Code: Select all
11Job started at 6/10/2015 4:00:00 PM6/10/2015 4:00:04 PM6/10/2015 4:00:04 PMSucceeded
23Building file tree6/10/2015 4:00:09 PM6/10/2015 4:00:06 PMSucceeded
35Preparing next server for processing6/10/2015 4:00:09 PM6/10/2015 4:00:09 PMSucceeded
47Processing MILIVVBACKUP016/11/2015 8:55:05 AM6/10/2015 4:00:10 PMSucceeded
59All hosts have been queued for processing6/11/2015 8:55:07 AM6/11/2015 8:55:07 AMSucceeded
611Unloading tape OZL534L4 from Drive 1 (Drive ID: Tape0) to Slot 216/11/2015 8:58:21 AM6/11/2015 8:55:08 AMSucceeded
7122 directories and 57 files backed up successfully6/11/2015 8:58:21 AM6/11/2015 8:58:21 AMSucceeded
813Load: Source 4% > Proxy 3% > Network 5% > Target 99%6/11/2015 8:58:26 AM6/11/2015 8:58:26 AMSucceeded
914Primary bottleneck: Target6/11/2015 8:58:26 AM6/11/2015 8:58:26 AMSucceeded
1015Job finished at 6/11/2015 8:58:26 AM6/11/2015 8:58:27 AM6/11/2015 8:58:27 AMSucceeded



It doesn't give me the files that were written to tape.
Also it seems to transpose the number of files and directories that are backed up.
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Mon Dec 21, 2015 3:15 pm

If the file is skipped by files to tape job (either if it doesn't already exist or if it is just locked by some process), there will be a warning in the said log, describing which file was skipped.

Having this information should be enough to understand whether the latest session was fully successful or not and which files might be deleted.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Mon Dec 21, 2015 3:27 pm

Not in my case, since i'm constantly replicating files to this target (nas to nas file replication)
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Mon Dec 21, 2015 5:11 pm

Hmm, you want to archive files that will be placed to the source directory during the job's execution? If so, it's not possible, as tree of files to copy is built during job's start.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Mon Dec 21, 2015 5:18 pm

Let me explain in more detail.

1. SQL trans logs go to primary storage (NAS @ colo)
2. NAS replicates to secondary storage (NAS @ main office)
3. Veeam backs up files from secondary storage to tape. (mapped drive on tape server, using system account to map as local letter)

Since Veeam is not doing the replication, files are still being copied to the NAS while others are written to tape. I only care about what has actually been written to tape, since new files will be caught on the next run.
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Wed Dec 23, 2015 12:34 pm

In this case, the first step would be indeed to create a list saying which files were copied and when. Something like the following:

Code: Select all
Asnp VeeamPSSNapin
foreach ($TapeCatalog in Find-VBRTapeCatalog)
{
$Info = ($TapeCatalog | select Name, Versions), ((Get-VBRTapeMedium | where {$_.mediafamilyitem.id -eq $TapeCatalog.Versions.Parts.backupset.MediaFamilyId}) | select barcode)
$Info | Format-Table -Property Name, Barcode, {$_.Versions.creationtime}
}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Wed Dec 23, 2015 2:49 pm

Code: Select all
Find-VBRTapeCatalog : No files found in the backup set 9eb7e38c-92e2-4820-b38b-20000a013dc8
At line:2 char:26
+ foreach ($TapeCatalog in Find-VBRTapeCatalog)
+                          ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-VBRTapeCatalog], Exception
    + FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Command.FindVBRTapeCatalog
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Wed Dec 23, 2015 4:45 pm

Does the same happen if you input the same command outside of the cycle:

Code: Select all
Find-VBRTapeCatalog


Or specify error action:

Code: Select all
Find-VBRTapeCatalog -ErrorAction SilentlyContinue


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Wed Dec 23, 2015 4:49 pm

Tried that, didn't work.

Code: Select all
PS C:\Windows\system32> Find-VBRTapeCatalog -ErrorAction SilentlyContinue
WARNING: This cmdlet is obsolete and no longer supported
Find-VBRTapeCatalog : No files found in the backup set 9eb7e38c-92e2-4820-b38b-20000a013dc8
At line:1 char:1
+ Find-VBRTapeCatalog -ErrorAction SilentlyContinue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-VBRTapeCatalog], Exception
    + FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Command.FindVBRTapeCatalog
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Re: post-job script need to delete files that were written.

Veeam Logoby v.Eremin » Thu Dec 24, 2015 12:12 pm

It seems that you happen to have backupset containing no files within it. Thus, the error.

Either try to check other error actions or query tape catalog so that the corresponding backup set is not returned.

Code: Select all
Find-VBRTapeCatalog | where {$_.Versions.backupsetId -ne "9eb7e38c-92e2-4820-b38b-20000a013dc8"}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: post-job script need to delete files that were written.

Veeam Logoby ccatlett1984 » Sun Dec 27, 2015 4:29 pm

Same error....

Using a where clause wont work, since that's filtering AFTER the find-vbrtapecatalog cmdlet returns its data.

Code: Select all
PS C:\Windows\system32> Find-VBRTapeCatalog | where {$_.Versions.backupsetId -ne "9eb7e38c-92e2-4820-b38b-20000a013dc8"}
WARNING: This cmdlet is obsolete and no longer supported
Find-VBRTapeCatalog : No files found in the backup set 9eb7e38c-92e2-4820-b38b-20000a013dc8
At line:1 char:1
+ Find-VBRTapeCatalog | where {$_.Versions.backupsetId -ne "9eb7e38c-92e2-4820-b38 ...
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-VBRTapeCatalog], Exception
    + FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Command.FindVBRTapeCatalog
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests