ROBOCOPY - Create Backup Script

Page 27 of 32 FirstFirst ... 172526272829 ... LastLast

  1. Posts : 1
    Windows 7 Home Premium 32bit
       #260

    Hi,

    I was looking for a simple backup programm, utility, ... to backup my files. The program should be portable. I like to backup one time all files (full backup) and then for the next seven times the difference (differential or incremental backup).

    I tried to tweak robocopy to make differential backups. With the option /MAXAGE I think I found a solution even if it's not a real differential backup because it's based only on date and not on date and time.

    I took the script from Post 13 and modified it.

    Some explanations:

    • robocopy didn't work correctly without administrator privileges. So I check that with fsutil.
    • I would like to use TARGETDIR as a variable in for example TARGETFULL. But that didn't work. So I wrote the target directory in all other TARGET variables.
    • The first time a full backup is made the delete command fails.

    Can anybody have a look on my modified script?

    Code:
    echo off
    mode con lines=45 cols=125
    
    :Start
    call :isAdmin
    if %errorlevel% == 0 (
    GOTO Menu
    ) else (
    echo Error: No administrator privileges.
    GOTO Quit
    )
    
    :isAdmin
    fsutil dirty query %systemdrive% >nul
    exit /b
    
    :Menu
    cls
    echo.
    echo ******************************
    echo *** Robocopy Backup Script ***
    echo ******************************
    echo.
    echo 1 - Run ROBO #1 - Full
    echo 2 - Run ROBO #2 - Diff
    echo 3 - Exit
    echo.
    echo ******************************
    echo.
    
    set day=%date:~-10,2%
    set month=%date:~-7,2%
    set year=%date:~-4%
    
    set hour=%time:~-11,2%
    set minute=%time:~-8,2%
    set second=%time:~-5,2%
    
    set source="<put_source_dir_here>"
    set targetdir="<put_target_dir_here>"
    set targetfull="<put_target_dir_here>\Full\%year%.%month%.%day%-%hour%.%minute%.%second%"
    set targetdiff="<put_target_dir_here>\Diff\%year%.%month%.%day%-%hour%.%minute%.%second%"
    set logfilefull="<put_target_dir_here>\%year%.%month%.%day%-%hour%.%minute%.%second%.full.log"
    set logfilediff="<put_target_dir_here>\%year%.%month%.%day%-%hour%.%minute%.%second%.diff.log"
    
    SET /P M=Type 1, 2 or 3 then press ENTER: 
    IF %M%==1 GOTO Full
    IF %M%==2 GOTO Diff
    IF %M%==3 GOTO Quit
    
    :Full
    del "%targetdir%\*.last_full"
    robocopy "%source%" "%targetfull%" /MIR /R:3 /W:3 /V /LOG+:"%logfilefull%" /TEE
    type NUL > "%targetdir%\%year%%month%%day%.last_full"
    pause
    GOTO MENU
    
    :Diff
    For /F %%i in ('dir /B %targetdir%\*.last_full') do set last_full=%%~ni
    robocopy "%source%" "%targetdiff%" /MAXAGE:%last_full% /R:3 /W:3 /V /LOG+:"%logfilediff%"
    pause
    GOTO MENU
    
    :Quit
    pause
    Best regards, Frank
      My Computer


  2. Posts : 1
    Windows 7 Enterprise
       #261

    Watch out for "/MIR"


    Nice article! A couple of suggestions:

    1. "/MIR" will delete unmatched files and directories on the destination - this may or may not be what you want. It is defined as:
    /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
    (/PURGE :: delete dest files/dirs that no longer exist in source.
    /E :: copy subdirectories, including Empty ones.)
    2. You may need to use "/XJ" if you are copying certain directories or files based on windows junction points. This will often be needed when you are copying from system-managed directory trees.

    David
      My Computer


  3. Posts : 8
    Windows 7 Pro x64 SP 1
       #262

    I've got a successful batch file using robocopy to back up certain files to an external hard drive and it needs to back up as often as possible. The source is a LONG path on the C drive and the destination is on the D drive.

    We have about 12 users who upload their files throughout the day (24/7) and these files are uploaded to the source parent folder. The users then drag and drop their files through a maze of folders about six levels beyond the parent folder.

    The problem I'm running into is that Task Scheduler is set to run the batch file every five minutes (the closest thing I could find to an instantaneous backup), which copies the files to whatever folder it happens to be in while users are moving them throughout the directory tree. This creates a lot of clutter. Does anyone know whether you can exclude any files from being copied from those folders until they get to their final destination other than writing a script for each specific folder?

    The reason I don't want to do this is because the folders are organized by year, then month, then user ID, then by purpose. This means that I would need to write hundreds of robocopy commands and then update them at least every year. I'd like to avoid that, if at all possible.

    EDIT: I have stayed away from /mir because deleting anything is a policy violation and, depending on what is deleted, possibly a violation of law.

    EDIT 2: Also, it is against policy to download third party software as well, so that idea is most likely not an option before it gets mentioned. However, admin might bend the rules depending on the software. So if anyone has some good suggestions, that would be great too.

    Thanks guys!
      My Computer


  4. Posts : 1
    Windows 7 Enterprise Service Pack 1 64-Bit
       #263

    RoboCopy with a Western Digital MyBookLiveDuo


    I have tried the simple copy command to test a backup .bat file but i keep getting this error.

    ERROR : Invalid Parameter #3 : "\\Z:\[FOLDER NAME]

    The MyBookLiveDuo drive is mapped with a public share (Z:\) and a folder that i want to use to back up to. I think that it has something to do with type of drive, i think it uses a different operating system than windows but works with windows, mac, etc.

    i am not too versed in all of this type of stuff so I may not even be describing my problem correctly. I am just hoping that someone has run across this before.

    Thanks
      My Computer


  5. Posts : 8
    Windows 7 Pro x64 SP 1
       #264

    Sheepdog110 said:
    I've got a successful batch file using robocopy to back up certain files to an external hard drive and it needs to back up as often as possible. The source is a LONG path on the C drive and the destination is on the D drive.

    We have about 12 users who upload their files throughout the day (24/7) and these files are uploaded to the source parent folder. The users then drag and drop their files through a maze of folders about six levels beyond the parent folder.

    The problem I'm running into is that Task Scheduler is set to run the batch file every five minutes (the closest thing I could find to an instantaneous backup), which copies the files to whatever folder it happens to be in while users are moving them throughout the directory tree. This creates a lot of clutter. Does anyone know whether you can exclude any files from being copied from those folders until they get to their final destination other than writing a script for each specific folder?

    The reason I don't want to do this is because the folders are organized by year, then month, then user ID, then by purpose. This means that I would need to write hundreds of robocopy commands and then update them at least every year. I'd like to avoid that, if at all possible.

    EDIT: I have stayed away from /mir because deleting anything is a policy violation and, depending on what is deleted, possibly a violation of law.

    EDIT 2: Also, it is against policy to download third party software as well, so that idea is most likely not an option before it gets mentioned. However, admin might bend the rules depending on the software. So if anyone has some good suggestions, that would be great too.

    Thanks guys!


    Disregard. I wrote commands for each final destination folder to solve this problem. Works like a charm. I was hoping to avoid that, but it needed to be done ASAP and other options were limited. If anyone knows an answer to this, it might still help someone else.
      My Computer


  6. Posts : 5
    Windows 7 Enterprise 32bit
       #265

    Something wrong?


    Here is my robocopy script I created that "worked" to backup user data to the server but I started it on Friday at around noon and it was still not done when the user came in this morning:

    Code:
    robocopy "c:\Users\Lamar" "\\grantserver09\Backup\LFowler12" /E /V /XO /XA:H /LOG:"Backup_Log.txt" /FFT /ZB /R:1 /W:1 /tee
    So I fixed up a quick XCopy script, emptied the folder on the server so it was a fair comparison, and that finished in about an hour:

    Code:
    xcopy "c:\Users\Lamar" "\\grantserver09\Backup\LFowler12" /c /d /e /g /i /r /s /y
    Is there something wrong with my robocopy script that would cause it to be so slow? I tried it with and without the /MT and it actually seemed to make it slower with it?
      My Computer


  7. Posts : 26,869
    Windows 11 Pro
       #266

    Chmcke01, can you tell me exactly what you are wanting to do? I am no expert with robocopy although I do use it. I am unfamiliar with some of the switches you are using and have not been able to find them. This can give you an idea of the switches and what they do http://social.technet.microsoft.com/...-examples.aspx

    You can also, in the command window use robocopy /? to get all of the options available. The MT command sets the number of threads to be used in the operation, the default being 8. Obviously, the amount of time it takes depends on how much data and they type of files you are copying.

    The quotation marks are not necessary unless to folders have spaces in the name. ie., LFowler needs no quotation marks, but L Fowler does need quotation marks.

    If we knew exactly what you are trying to do, it may help us. I am sure Golden will be around later this evening and be much better help than I am.
      My Computer


  8. Posts : 5
    Windows 7 Enterprise 32bit
       #267

    Script


    essenbe said:
    Chmcke01, can you tell me exactly what you are wanting to do? I am no expert with robocopy although I do use it. I am unfamiliar with some of the switches you are using and have not been able to find them. This can give you an idea of the switches and what they do Robocopy and a Few Examples - TechNet Articles - United States (English) - TechNet Wiki

    You can also, in the command window use robocopy /? to get all of the options available. The MT command sets the number of threads to be used in the operation, the default being 8. Obviously, the amount of time it takes depends on how much data and they type of files you are copying.

    The quotation marks are not necessary unless to folders have spaces in the name. ie., LFowler needs no quotation marks, but L Fowler does need quotation marks.

    If we knew exactly what you are trying to do, it may help us. I am sure Golden will be around later this evening and be much better help than I am.
    I provide IT support for a small business with about 5 users each with their own computer. Their last IT guy setup Retrospect backup backing up the user folder to the server and then CrashPlan Pro was installed on the server to backup to their cloud service (because they let you backup an unlimited amount of data on a single computer for $10 per month).

    The first problem was that Retrospect doesn't save the data in a format that can be easily viewed to compare the backed up copy to the copy still on the original drive. The next problem was that one of the users got a message that their computer hadn't backed up in a few days so they uninstalled it from the server and reinstalled it but now it is asking for the key which nobody knows.

    So, I figured for so few users I could make a basic xcopy script set to run at login and I did and it worked...but several people have told me that robocopy is worlds better than xcopy.

    Which switches are you not familiar with? /XA:H excludes hidden files, /fft is Fat File Timing which several sites recommended for transfers over the network, /tee displays output to the cmd window in addition to the log. Without it if you have the log turned on then it looks like nothing is happening in the window and I feared the users would close it out if it didn't look like it was doing anything.
      My Computer


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

    I am hoping Golden will help with your problem, but for what it's worth, I use the following for my backups

    robocopy <source> <destination> /e /mir /np /tee /mt:10 /log:backup_log.txt For your purposes I would add the z switch.
      My Computer


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

    Thanks for all the info.

    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.

    To copy files you simply add the source file after the desination folder. For Example:

    ROBOCOPY "source folder" "destination folder" "file from source folder" /DCOPY:T /COPY:DAT /E

    It's also easy to batch copy many files by creating a .bat with each line one after the other. Don't call the file robocopy though or it will just run an endless loop.

    BTW is /DCOPY:T redundant when using /COPY:DAT ? I assume it is, but it's never caused ant issues so I've always just used them both.

    Regards,

    Alan.
      My Computer


 
Page 27 of 32 FirstFirst ... 172526272829 ... 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 18:26.
Find Us