Robocopy issue
Posted: 23 Jan 2023 13:32
Im trying to make a bat file that i can use with task scheduler to backup documents every day and then after 7 days id like it to delete the oldest day. Problem is, when this destination folder is created its created with the right timestamp first, then instantly changes to an older date then it gets instantly deleted. Note its the same issue if i use /MIR instead of /e, or remove /xo.
Any help is appreciated, thanks!
Code: Select all
set to=%~dp0
set from1=C:\Users\Insomnijack\Documents
set command=/e /xo /R:2 /W:1 /Xf backupalternative.bat
set deletein=7
robocopy %from1% %to%\%date:/=_% %command%
ForFiles /p %to% /d -%deletein% /c "cmd /c IF @isdir == TRUE rd /S /Q @path"