Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15940

Filtering FORFILES in batch files

$
0
0

I'm trying to write a batch file to run on Task Scheduler on Windows server to delete some PostgreSQL archived files.

Thought I use FORFILES and the following will list all the .backup files in the archived folders.

SET "log=%USERPROFILE%\temp\delete.log"SET "target.dir=\\UNC_path\pgsql_arch"pushd "%target.dir%"FORFILES /S /D -30 /M *.backup /C "cmd /c echo @file"popd

The *.backup file is a 1kb and in PostgreSQL, it looks like information of what the backup contains. I do not want to delete those - what I'm trying to get is the the last file of the 30th day so I can pass into pg_archivecleanup to let it do its thing.

For example, today is 2/22/2024 - so essentially I'm trying to get the .backup filename for 1/21/2024 to pass into pg_archivecleanup to delete all archived files older than 1/21/2024.

Question, is it possible to filter the list that FORFILES returns to just 1 single filename? If so, how can I do that?

I welcome any other suggestions. This is windows and it's a single PostgreSQL to support 3rd party vendor product.

Thank you

Tried

SET "log=%USERPROFILE%\temp\delete.log"SET "target.dir=\\UNC_path\pgsql_arch"pushd "%target.dir%"FORFILES /S /D -30 /M *.backup /C "cmd /c echo @file"popd

Expecting:Need just single row from FORFILES results.


Viewing all articles
Browse latest Browse all 15940

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>