Copying backup files from a network drive daily, need different dated copies for the end of each day

StackOverflow https://stackoverflow.com/questions/23683535

문제

I am trying to backup files from a network drive to my C: drive. for the copy I am using:

xcopy "\MY_SERVER_IP\SharedDRIVE\TEST*" "C:\Test_Folder" /D /E /C /I /H /Y

Is there any way I can have the date added onto this and the information not replace but instead compound and have a daily record of changes made to the files but not lose older copies? This will work for copying the most current information, but I need many months of records not just the most current copy.

Any suggestions?

Thanks in advance

도움이 되었습니까?

해결책

This is a way of getting a DateTime string independent of localization:

for /f "tokens=1 delims=." %%i in ('wmic os get localdatetime^|find "."') do set dt=%%i

This is format YYYYMMDDHHMMSScc

You can shorten this string to your needs. for example:

set dt=%dt:~0,8%

will set it to YYYYMMDD only.

set dt=%dt:~0,12%

will set it to YYYYMMDDHHMM

Then you can copy like this:

xcopy "\MY_SERVER_IP\SharedDRIVE\TEST*" "C:\Test_Folder_%dt%" /D /E /C /I /H /Y
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top