Batchfile to create backup and rename with timestamp

后端 未结 5 859
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 20:35

I have the following network path to copy the file to an archive folder. It copies File 1 from Folder to Archive but I would like to add t

5条回答
  •  执念已碎
    2021-01-31 21:18

    I've modified Foxidrive's answer to copy entire folders and all their contents. this script will create a folder and backup another folder's contents into it, including any subfolders underneath.

    If you put this in say an hourly scheduled task you need to be careful as you could fill up your drive quickly with copies of your original folder. Before bitbucket etc i was using as similar script to save my code offline.

    @echo off
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
    set YYYY=%dt:~0,4%
    set MM=%dt:~4,2%
    set DD=%dt:~6,2%
    set HH=%dt:~8,2%
    set Min=%dt:~10,2%
    set Sec=%dt:~12,2%
    
    set stamp=YourPrefixHere_%YYYY%%MM%%DD%@%HH%%Min%
    rem you could for example want to create a folder in Gdrive and save backup there
    cd C:\YourGoogleDriveFolder
    mkdir %stamp%
    cd %stamp%
    
     xcopy C:\FolderWithDataToBackup\*.* /s 
    

提交回复
热议问题