I have a users XP computer that has a DB where some files are created and or updated daily and I want to make a script so that the DB is incrementally updated (not copied) for a period of 90days. All files/folders within DB older than 90days should be deleted. This way I can control the DB size to no more than 90days of last modified retention.
Here's is what I have so far and it's basically deleting everything every other day. I'll remind everyone that it's on an XP box and that the syntax for forfiles is different than that of Win7 (since I have to install forfiles on XP and that's the only ver I could find)
I'm a little green at DOS script and I haven't programmed for a while so please excuse the tidiness of the script.
Code: Select all
@ECHO
CLS
SETLOCAL ENABLEDELAYEDEXPANSION
SET unit_num=21
NET USE S: /delete
NET USE S: \\10.xxx.xxx.xx\xxx xxx_xxx /USER:xxx%unit_num%\xxx
::Setting Variables
SET max_days_db=90
SET max_days_log=10
SET today=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET sourcedrive=d:\db\*.*
SET backupdrive=s:\unit%unit_num%\
SET logfile=%backupdrive%logs\%today%_backup_log.txt
ECHO %today% %time% Backup Starting>>%logfile%
ECHO Files being backed up from %sourcedrive% to %backupdrive%db ...>>%logfile%
ECHO.>>%logfile%
XCOPY "%sourcedrive%" "%backupdrive%db" /d /e /c /i /h /r /k /y >>%logfile%
IF ErrorLevel 0 @Echo Files Copied Without Error>>%logfile%
IF ErrorLevel 1 @Echo No Files Found to Copy>>%logfile%
IF ErrorLevel 2 @Echo User Pressed CTRL+C To Stop Backup>>%logfile%
IF ErrorLevel 4 @Echo Invalid Drive or Low Memory>>%logfile%
IF ErrorLevel 5 @Echo Disk Write Error Occured>>%logfile%
ECHO.>>%logfile%
ECHO %time% Backup to %backupdrive%db Complete>>%logfile%
::Start a log of all deleted files
ECHO.>>%logfile%
ECHO %time% Deleting folders older than %max_days_db% days Started>>%logfile%
ECHO Folders being deleted from %backupdrive%db ... >>%logfile%
ECHO.>>%logfile%
::Delete folders older than %max_days_db% days in %backupdrive%
FORFILES -p%backupdrive%db\ -m*.* -s -d-%max_days_db% -c"CMD /c IF @ISDIR==TRUE RD /s /q @PATH"2>NUL>>%logfile%
::Delete log files older than %max_days_log% Days in the Log File directory
ECHO.>>%logfile%
ECHO %time% Deleting log files older than %max_days_log% days Started>>%logfile%
ECHO Files being deleted from %backupdrive%logs ...>>%logfile%
ECHO.>>%logfile%