-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
post-job script need to delete files that were written.
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?
Do any cmdlets exist that would let me list the files written to tape for the current run of the job?
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
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?
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
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
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
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
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
- Check whether the latest job result was successful
- In case of positive answer get the latest job session
- Get the 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.
- Get a Tape Job
Code: Select all
$TapeJob = Get-VBRTapeJob -name "Name of your tape job"
Code: Select all
$TapeJob.LastResult -eq "Success"
Code: Select all
$Session = Get-VBRSession -Job $TapeJob -Last
Code: Select all
$Log = $Session.log
- In case of positive answer delete the files in given directory (you've said that this part is not a problem for you)
Thanks.
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
$log gives useless data.
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.
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.
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
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.
Having this information should be enough to understand whether the latest session was fully successful or not and which files might be deleted.
Thanks.
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
Not in my case, since i'm constantly replicating files to this target (nas to nas file replication)
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
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.
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
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.
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.
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
In this case, the first step would be indeed to create a list saying which files were copied and when. Something like the following:
Thanks.
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}
}
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
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
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
Does the same happen if you input the same command outside of the cycle:
Or specify error action:
Thanks.
Code: Select all
Find-VBRTapeCatalog
Code: Select all
Find-VBRTapeCatalog -ErrorAction SilentlyContinue
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
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
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
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.
Thanks.
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"}
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
Same error....
Using a where clause wont work, since that's filtering AFTER the find-vbrtapecatalog cmdlet returns its data.
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
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
Should I open a support case to remove the backup sets that contain no files?
I really need to get this working.
I really need to get this working.
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: post-job script need to delete files that were written.
I think it's a way to go, as I'm not aware of any way to delete them via PowerShell. Moreover, such corrections should be better conducted under direct supervision of competent engineer. Thanks.
-
- Enthusiast
- Posts: 83
- Liked: 9 times
- Joined: Oct 31, 2013 5:11 pm
- Full Name: Chris Catlett
- Contact:
Re: post-job script need to delete files that were written.
I ended up attacking this problem a whole different way.
I am directly querying SQL for files that were written to tape, and then looping through them and removing them off the storage.
(Not the most efficient, but it works well and isn't dependent on cmdlets.)
I am directly querying SQL for files that were written to tape, and then looping through them and removing them off the storage.
(Not the most efficient, but it works well and isn't dependent on cmdlets.)
Code: Select all
#Connect to SQL
$dataSource = “BACKUP01\VEEAMSQL2012”
$database = “VeeamBackup”
$connectionString = “Server=$dataSource;Database=$database;Integrated Security=True;”
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
#Get files Veeam wrote to Tape, excluding "Backup" files (Since we only want the sql files we backed up.)
$connection.Open()
$query = “SELECT * FROM [VeeamBackup].[dbo].[Tape.report_file_changes] WHERE name NOT LIKE '%Backup%'”
$command = $connection.CreateCommand()
$command.CommandText = $query
#Pull the result of the query into a powershell object
$result = $command.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($result)
$table = $table | sort name
#Select only the files that came from the FINSQL folder
$FINSQL_Files = $table | Where-Object {$_.directory_id -eq "20"}
#Select only the files that came from the NTSQL1 folder
$NTSQL1_Files = $table | Where-Object {$_.directory_id -eq "21"}
#Remove files from the Southfied NAS, That have successfully gone to tape.
Foreach ($file in $FINSQL_Files)
{
$file = $file.name
IF(Test-Path \\nas01\sqlbackup\FINSQL\$file)
{
Remove-Item \\nas01\sqlbackup\FINSQL\$file -Force -verbose
}
}
#Remove files from the Southfied NAS, That have successfully gone to tape.
Foreach ($file in $NTSQL1_Files)
{
$file = $file.name
IF(Test-Path \\nas01\sqlbackup\NTSQL1\$file)
{
Remove-Item \\nas01\sqlbackup\NTSQL1\$file -Force -verbose
}
}
Who is online
Users browsing this forum: No registered users and 9 guests