if there is more then 1 file then delete old files
Posted: 15 Dec 2011 01:55
i run a backup to a share and i need to delete old backup's
otherwise my share will run out of disk space
now i run this in file in Scheduled Tasks
@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST
:SECOND
forfiles /p d:\bacup /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL"
GOTO END
:FIRST
forfiles /p d:\backup /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL"
GOTO END
:END
wich works fine, but i need to keep at least 1 file.
so if my backup fails for 2 days, this file will delete my last good backup.
i need to add that i will always keep the last file in this directory.
so something like, if there is only one file then DONT delete anything.
thanks
otherwise my share will run out of disk space
now i run this in file in Scheduled Tasks
@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST
:SECOND
forfiles /p d:\bacup /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL"
GOTO END
:FIRST
forfiles /p d:\backup /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL"
GOTO END
:END
wich works fine, but i need to keep at least 1 file.
so if my backup fails for 2 days, this file will delete my last good backup.
i need to add that i will always keep the last file in this directory.
so something like, if there is only one file then DONT delete anything.
thanks