PowerShell script exchange
Post Reply
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

How to say "No to all" automatically during old file deletion

Post by Kiranpn »

Hi team,
I have below script to delete the old files:

Get-ChildItem -Path "D:\VeeamSilo1\TEST Folder"-Recurse -Exclude *.vbm |

Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-0)}| #Finding the last 28 days of data
ForEach-Object {
$_ | del -Force
$_.FullName, $_.LastWriteTime | Out-File C:\temp\report_3.txt -Append
}

But I am getting the pop-up window with below message:
"The item at Microsoft.PowerShell.Core\FileSystem::D:\VeeamSilo1\TEST Folder|New folder has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?"
[Yes] [Yes to All] [No] [No to All] [Suspend]
Image

How to say [No to All] automatically with sript. I tried "Try catch" method but it is not working.
https://stackoverflow.com/questions/202 ... nfirmation


Regards,
Kiran
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How to say "No to all" automatically during old file deletion

Post by david.domask »

Hi @Kiranpn,

Can I ask, are you using this for your own retention? It's just I see you exclude .VBM files, which would only show in our Backup Repository directories (or should). In short, I strongly recommend against trying to make your own file retention, this has a high potential to result in unexpected dataloss.

Your code is failing because when you hit the directory, you're calling Remove-Item without the -Recurse flag.

This gets to a bit of a problem because you call Get-ChildItem with -Recurse, which will return:

- All Directories under your path
- All items inside those directories
- All items on the top level directory

The issue happens if you delete the Directories first even with the -Recurse flag, because consider if the list looks like this:

Dir1
Dir1/someitem.txt
Dir1/someimem2.txt

By deleting these in a loop, even if you add the -Recurse flag, the loop will delete Dir1 and all of its contents, then it will try to delete the two items underneath it, but throw an error.

There easiest solution in my mind is

1. Do two passes on the directory; first time add the -Attributes !Directory parameter to exclude directories and just clean the items, then the second time clean the directories

But again, I must stress that if this is to manage retention of active backups, please do not do this as likely it will result in unexpected data loss.
David Domask | Product Management: Principal Analyst
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: How to say "No to all" automatically during old file deletion

Post by Kiranpn »

Hi David,
Thank you for the reply.
We have this script to remove old Oracle RMAN data from offsite location.
We have 30 days retention, but Veeam is not deleting old files automatically in offsite silo and filling our space.
They are TB of space and just filling up the space with the old data.
We have support ticket with Veeam now, and manually deleting older data (more than 30 days) at the moment.
I created this script (removed the original path here on this script) to remove those data excluding metadata (.vbm) file.
Currently script is deleting those old data (mostly they are, for example, "LOG_OIDSEPRD_112817_1309_1_1.vab" and "c-381146-2023-11_RMAN_AUTOBACKUP.vab" in Oracle RMAN Plugin folder in offsite Silo)

When we select "No to all" it runs and delete the files on first folder (if there is 2nd folder inside 1st folder it skips that 2nd folder).

We have hundreds of folders and thousands of old .vab files which is very hard to delete manually.

And thank you for the suggestion below to rectify the problem, I will explore that too :)

Regards,
Kiran
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How to say "No to all" automatically during old file deletion

Post by david.domask »

Hi @Kiranpn, I would actually wait for the investigation to complete, as the deletion should be done automatically.

Confirm with your Veeam Engineer if it's safe to manually clear the files, because we may still be tracking them, and this can potentially cause further issues.

What I wrote will still help here, so please review it, but wait for confirmation from your Support Engineer it's safe to delete the files manually.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests