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

24 May 2016   #270
essenbe

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

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
Quote:
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 System SpecsSystem Spec
.
24 May 2016   #271
xFiReStOrMx

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

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 System SpecsSystem Spec
24 May 2016   #272
essenbe

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

Quote   Quote: Originally Posted by xFiReStOrMx View Post
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
Quote:
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 System SpecsSystem Spec
24 May 2016   #273
xFiReStOrMx

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

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 System SpecsSystem Spec
.

27 Jun 2016   #274
d95gas

Windows 7 Enterprise 64 bits
 
 

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 System SpecsSystem Spec
01 Jul 2016   #275
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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%"


Quote   Quote: Originally Posted by xFiReStOrMx View Post
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.
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 System SpecsSystem Spec
07 Oct 2016   #276
chrishammond

Win7 Ult x64
 
 
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
My System SpecsSystem Spec
08 Oct 2016   #277
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by chrishammond View Post
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 System SpecsSystem Spec
08 Oct 2016   #278
essenbe

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

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 System SpecsSystem Spec
08 Oct 2016   #279
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by essenbe View Post
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 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 15:02.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App