• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Scripting help: Deleting files more than 3 days old

I have the following script (SEE BELOW) running to automate my backups using 2003 Server.  The script makes th ebackup, then copies the bkf to a remote server.

The last peice of the puzzle is to do some cleanup

1. delete the bkf files that reside in the source folder one they are copied to the source folder
2.  Delete any bkfs older than3 days so I always have the last 3 backups availlable for restore.
********************************************************************************************************************
@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i-%%j-%%k-%%l
@set dt=%dt%
@echo Copying backup set:  %dt%.
@echo Please wait...
@ntbackup.exe backup "@C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows

NT\NTBackup\data\backup set.bks" /a /d "STVPCSG01 %dt%" /v:no /r:no /rs:no /hc:off /m normal /j "%dt%" /l:s /f

"c:\Auto Backups\STVPCSG01 %dt%.bkf"


@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i-%%j-%%k-%%l
@set dt=%dt%
@echo Sending backup file to STVPDPM01. Please wait...
@xcopy "c:\Auto Backups\STVPCSG01 %dt%.bkf" "\\STVPDPM01\DMZ$" /Y
@echo Finished.


0
pflecha
Asked:
pflecha
  • 5
1 Solution
 
popularbhaskarCommented:
try the FORFILES.EXE server resource kit tool - works on NT, 2000, XP, 2003, etc

example:
FORFILES -pc:\foldername -s -m*.* -d-30 -c"CMD /C del @FILE"

-p = path
-s = include subdirs
-m = match filetype
-d = age in days (can also be set as an absolute date ie DDMMYYYY)
-c = command to execute

Note there are no spaces between the switches and their arguments.
info here:
http://www.jsiinc.com/SUBL/tip5600/rh5645.htm
Download it here:
http://www.dynawell.com/support/ResKit/winnt.asp
http://www.dynawell.com/support/ResKit/

--popularbhaskar
0
 
pflechaAuthor Commented:
It is deleting all files regardless of the date of the file

FORFILES /p "D:\DMZ$" /D -5 /M *.vhd -c "CMD /c del *.vhd"

Does the -5 mean to delete any files older than 5 days?  That is my goal.
0
 
pflechaAuthor Commented:
Does anybody have experience using the FORFILES to delete files older than a specific date?  I need to automate the capacity management of a specific folder.   Any files older than 5 days need to be deleted.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pflechaAuthor Commented:
The command I am trying is

FORFILES /p "c:\backups" /D -5 "cmd /c *.bkf"
0
 
pflechaAuthor Commented:
Does anybody know how I can  automate the deletion of these files?
0
 
pflechaAuthor Commented:
OK I figured it out.


Forfiles -p D:\FOLDER -m *.bkf -d -10 -c "CMD /C del @file"
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now