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

PowerShell script exchange

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

Veeam Logoby ccatlett1984 » Thu Jan 14, 2016 5:29 pm

Should I open a support case to remove the backup sets that contain no files?

I really need to get this working.
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 » Fri Jan 15, 2016 9:34 am

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.
v.Eremin
Veeam Software
 
Posts: 13291
Liked: 973 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 Feb 15, 2016 7:43 pm

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.)
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
    }
}
ccatlett1984
Enthusiast
 
Posts: 83
Liked: 9 times
Joined: Thu Oct 31, 2013 5:11 pm
Full Name: Chris Catlett

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests