Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: ROBOCOPY - Create Backup Script

22 Feb 2016   #260
frajoti

Windows 7 Home Premium 32bit
 
 

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 System SpecsSystem Spec
.
07 Mar 2016   #261
anyoneis

Windows 7 Enterprise
 
 
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 System SpecsSystem Spec
22 Mar 2016   #262
Sheepdog110

Windows 7 Pro x64 SP 1
 
 

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 System SpecsSystem Spec
07 Apr 2016   #263
apc7468

Windows 7 Enterprise Service Pack 1 64-Bit
 
 
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 System SpecsSystem Spec
.

08 Apr 2016   #264
Sheepdog110

Windows 7 Pro x64 SP 1
 
 

Quote   Quote: Originally Posted by Sheepdog110 View Post
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 System SpecsSystem Spec
03 May 2016   #265
chmcke01

Windows 7 Enterprise 32bit
 
 
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 System SpecsSystem Spec
03 May 2016   #266
essenbe

Windows 7 Enterprise X64/Windows 10 Enterprise X64/Windows 10 Pro X64/Linux Mint
 
 

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 System SpecsSystem Spec
03 May 2016   #267
chmcke01

Windows 7 Enterprise 32bit
 
 
Script

Quote   Quote: Originally Posted by essenbe View Post
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 System SpecsSystem Spec
05 May 2016   #268
essenbe

Windows 7 Enterprise X64/Windows 10 Enterprise X64/Windows 10 Pro X64/Linux Mint
 
 

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 System SpecsSystem Spec
24 May 2016   #269
xFiReStOrMx

Windows 7 Home Premium 64bit / Windows 10 Pro 64bit
 
 

Thanks for all the info.

I am curious however why it states the following:

Quote:
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 System SpecsSystem Spec
Comment

 ROBOCOPY - Create Backup Script




Tutorial Tools Search this Tutorial
Search this Tutorial:

Advanced Search




Similar help and support threads
Windows 7 Tutorial Category
robocopy script is not working through Scheduler
Dear All, My batch file of robocopy is working fine. But when I tried to run it through task scheduler, none of the files transfer to the target location. @echo off echo +-----------------------------------------+ echo Database Export Utility for server ...
General Discussion
Robocopy Backup - ERROR 5 (0x00000005)
Hi, I'm wondering if anyone might be able to shed some light on why I am getting the following such errors when running a robocopy batch file (as administrator) which cause the backup script to stall (- albeit temporarily): I am using the following backup command: robocopy "%srcPath%\My...
Backup and Restore
How 2 create a script/BAT or something that changes my desktop image?
Okay so I just got this program called Transparent Screen Lock and you can run files when the program starts/locks and closes/unlocks. What I would like to do is create a script or something that changes my desktop background to an image when I click "lock" and another script to change the desktop...
Customization
Robocopy backup for personal folders
I have created a batch file for copying my Documents folder to an external hard drive: The log file shows that it is backing up C:\users\USERNAME\documents\My Music and C:\users\USERNAME\documents\My Pictures. That's fine, because I want those backed up anyway, but when I go to...
Backup and Restore
I Need Help To Create REG. Script With Admin. Priv. For Reg. Editor?
Hello. I have a technical question/issue I wish to ask. I hope someone can help me. I am looking help for someone to modify or rewrite for me a simple system registry script for my context menu that allows or forces to "run as administrator" privileges automatically when I click on the...
Customization
Anyone use robocopy to backup?
Evening all, Just curious to know if anyone uses the built in utility to backup software on your machine, im trying to backup my itunes folder to an external HD but having a few issues to get this to work properly! I also use sync toy for backing up but just really want to know what everyone...
Backup and Restore


Our Sites

Site Links

About Us

Find 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 05:39.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App