ROBOCOPY - Create Backup Script

Page 28 of 32 FirstFirst ... 182627282930 ... LastLast

  1. Posts : 26,869
    Windows 11 Pro
       #270

    Alan, robocopy is a folder copier. It copies one folder to another folder. The switches allow you to determine what is copied. In your post above
    ROBOCOPY "source folder" "destination folder"
    You are copying "Source Folder" to "Destination Folder", both being folders. The switches determine what is copied. a /mir switch will copy the folder and all contents ie. mirror. Of course it copies the files inside the folder. It would make little sense to copy an empty folder without the files and folders inside too.

    The default copy flags is DAT, DCOPY:T copies the directory time stamps. Whether it also copies the Security and attributes, I don't know as I don't use them. My guess is that they would be somewhat different. Every command seems to be somewhat different.
      My Computer


  2. Posts : 4
    Windows 7 Home Premium 64bit / Windows 10 Pro 64bit
       #271

    Thank you for your reply. I am quite aware of this, however I am simply pointing out that the NOTE is wrong. It plainly states that "the source and destination syntax arguments in ROBOCOPY can only be folder names." which is wrong, you can also add a syntax for a specific file.

    There is other uses to ROBOCOPY than just copying the entire flolder, sometimes its useful to copy specific files only and also use ROBOCOPY's features, it's syntaxes.

    Regards,

    Alan
      My Computer


  3. Posts : 26,869
    Windows 11 Pro
       #272

    xFiReStOrMx said:
    Thank you for your reply. I am quite aware of this, however I am simply pointing out that the NOTE is wrong. It plainly states that "the source and destination syntax arguments in ROBOCOPY can only be folder names." which is wrong, you can also add a syntax for a specific file.

    There is other uses to ROBOCOPY than just copying the entire flolder, sometimes its useful to copy specific files only and also use ROBOCOPY's features, it's syntaxes.

    Regards,

    Alan
    Correct, that's why I said
    The switches determine what is copied
    It is still copied one folder to another folder, the switches determined what type files are or are not copied.
      My Computer


  4. Posts : 4
    Windows 7 Home Premium 64bit / Windows 10 Pro 64bit
       #273

    Fair enough. I am only pointing out that it can be used to copy specific files instead of whole folders. I use this sometimes to copy multiple specific files (for example files I want to keep data on i.e. using the DAT).
      My Computer


  5. Posts : 2
    Windows 7 Enterprise 64 bits
       #274

    Cry for help ..... and I know I should go through all 28 pages again as I think the answer is probably here, but having had a skim through, I cannot see it.

    Looking to use Robocopy to backup c:\SOURCE to :d:\SOURCE with date

    I would want a different folder for each night, either in dd/mm/yy format or even just day of the week "Monday, Tuesday, etc" on a 4 week cycle.

    I have tried various things but all seem to fail, as the data is critical and I am up against the clock, I thought I would just ask the question and see what comes back.


    Many thanks
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #275

    D95gas,

    Your batch file can do that. All you need to get the script to do is create a folder with the desired date, then perform a Robocopy to that folder.

    Here’s something you may modify to your liking.
    Code:
    @echo off
    setlocal EnableDelayedExpansion
    
    set "source=C:\SOURCE"
    set "destination=D:\SOURCE"
    set "destination_new_foldername=`YEAR-`MONTH-`DAY"
    
    goto :main
    :GetUTCDateTime
    setlocal EnableDelayedExpansion
    	for /f "delims=" %%D in (' wmic OS get LocalDateTime ^| find "." ') do (
    		set "dt=%%~D"
    		set "DATETIME.YEAR=!DT:~0,4!"
    		set "DATETIME.MONTH=!DT:~4,2!"
    		set "DATETIME.DAY=!DT:~6,2!"
    		set "DATETIME.HOUR=!DT:~8,2!"
    		set "DATETIME.MINUTE=!DT:~10,2!"
    		set "DATETIME.SECOND=!DT:~12,2!"
    		set "DATETIME.FRACTIONS=!DT:~15,6!"
    		set "DATETIME.OFFSET=!DT:~21,4!"
    		if "%DATETIME.HOUR%" gtr "11" (set DATETIME.PERIOD=PM) else set "DATETIME.PERIOD=AM"
    	)
    	for /f "delims=" %%I in (' date /t ') do (
    		set "dayofweek=%%~I"
    		set "DATETIME.DAYOFWEEK=!DAYOFWEEK:~0,3!"
    	)
    endlocal & (
    	set "DATETIME.YEAR=%DATETIME.YEAR%"
    	set "DATETIME.MONTH=%DATETIME.MONTH%"
    	set "DATETIME.DAY=%DATETIME.DAY%"
    	set "DATETIME.HOUR=%DATETIME.HOUR%"
    	set "DATETIME.MINUTE=%DATETIME.MINUTE%"
    	set "DATETIME.SECOND=%DATETIME.SECOND%"
    	set "DATETIME.FRACTIONS=%DATETIME.FRACTIONS%"
    	set "DATETIME.OFFSET=%DATETIME.OFFSET%"
    	set "DATETIME.PERIOD=%DATETIME.PERIOD%"
    	set "DATETIME.DAYOFWEEK=%DATETIME.DAYOFWEEK%"
    )
    goto :eof
    
    :main
    
    if not exist "%SOURCE%"\* echo Source location not found& exit /b 1
    if not exist "%DESTIN%"\* echo Destination location not found& exit /b 1
    
    call :GetUTCDateTime
    for %%I in (`YEAR `MONTH `DAY `HOUR `MINUTE `SECOND `FRACTIONS `OFFSET `PERIOD) do (
    	set "timeunit=%%~I"
    	call call set "destination_new_foldername=!DESTINATION_NEW_FOLDERNAME:%%~I=%%%%DATETIME.%%TIMEUNIT:~1%%%%%%!"
    )
    
    if exist "%DESTINATION%\%DESTINATION_NEW_FOLDERNAME%"\* (
    	echo Destination folder already contains a folder with name "%DESTINATION_NEW_FOLDERNAME%"
    	exit /b 1
    )
    
    robocopy "%SOURCE%" "%DESTINATION%\%DESTINATION_NEW_FOLDERNAME%"


    xFiReStOrMx said:
    I am curious however why it states the following:

    ROBOCOPY is a FOLDER copier, not a FILE copier - the source and destination syntax arguments in ROBOCOPY can only be folder names.
    This is totally false and ROBOCOPY can absoltutely copy single files.
    Good catch of detail. While the text in blue is a correct statement, I agree that calling Robocopy a folder copier is not right. Robocopy most definitely has the capability to copy single files, so calling the tool a folder copier would certainly be misleading.
      My Computer


  7. Posts : 7
    Win7 Ult x64
       #276

    Robocopy & Nas to External USB 2tb HDD


    First of all thanks so much for an excellent tutorial - I'm wondering if there is a way of using robocopy or another batch file to run backups from a NAS to an external USB

    Let me explain... (long winded I apologise)

    Recently a friend has been hit with locky variant .odin - and like a jack*ss backups never get done

    The old excuse 'no time' or 'I'll do it tomorrow' (I think he's a party animal) He uses a programme to backup the systems weekly to the NAS - (came free with the device) but relies on him plugging in the external drive and dragging/dropping files onto said external system...

    I would assume that robocopy would (if the network drive was mapped) be able to find the files and then back them up without him having to do a lot of stuff

    Now herein lies a problem - the only batch file I have ever edited was a simple one line affair that listed contents of a directory (you had to drop the bat into the file you wanted to list - then it would run alphabetical list and add filelist.txt and a few other things to the directory) and the only programming skill he has is the microwave oven

    I'm not asking for a custom script (though it would be appreciated) but I do want to have a go at doing it myself as then I can also use it with a few alterations for myself



    I swear if I ever meet the b*stards I'd rip them a few more holes

    I forgot one important detail - the NAS is used by computers in almost every room ( i dont think he has one in the loo) and needs to be seen on the network
    Last edited by chrishammond; 07 Oct 2016 at 18:02. Reason: Detail Added after the fact
      My Computer


  8. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #277

    chrishammond said:
    Now herein lies a problem - the only batch file I have ever edited was a simple one line affair that listed contents of a directory (you had to drop the bat into the file you wanted to list - then it would run alphabetical list and add filelist.txt and a few other things to the directory) and the only programming skill he has is the microwave oven
    Lucky you, the Robocopy command requires only one line by default.

    So what’s the problem?
      My Computer


  9. Posts : 26,869
    Windows 11 Pro
       #278

    This may help for the batch file or command

    Code:
    rem --- Edit the lines below to create your own backup strategy
    rem --- Add more lines for each new folder requiring backup
    rem --- Specified 4 threads to use for multi-threaded copying
    rem --- The results of the backup can be found in my_backup_log.txt 
    robocopy <source> <destination> /e /np /tee /mt:4 /log:my_backup_log.txt
    robocopy <source> <destination> /e /np /tee /mt:4 /log+:my_backup_log.txt
    robocopy <source> <destination> /e /np /tee /mt:4 /log+:my_backup_log.txt
    pause
    You can save the command to notepad and give it a name with the .bat extension and it will create a batch file. This one of my data backup files I use.

    Code:
    echo
    robocopy E:\users X:\Robocopy_W10_Data /e /mir /np /tee /mt:10 /log:backup_log.txt
    pause
    Name it Robocopy.bat and it will be a batch file. Just click it and it will run. You can automate it if you want by adding a nw Task in Task Scheduler Task Scheduler - Create New Task
      My Computer


  10. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #279

    essenbe said:
    Name it Robocopy.bat and it will be a batch file. Just click it and it will run.
    Except don’t name it “Robocopy” or big problems.
      My Computer


 
Page 28 of 32 FirstFirst ... 182627282930 ... LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:45.
Find Us