Robocopy Russian folder names. Backing up data using the Robocopy utility. Backup using robocopy

Part 1: Creating a backup script.

Robocopy(Robust File Copy) is a command line utility for replicating (copying) files and folders, which is available in the Windows Vista, Windows 7 and Windows Server 2008 operating systems.

Robocopy is designed for fault-tolerant copying of directories and directory trees. It has the ability to copy all (or selected) NTFS attributes and properties, and has additional restart code when used with a network connection in case of a break.

The Robocopy utility also exists in a graphical interface (GUI) who developed Derk Benish(Derk Benisch), systems engineer of the MSN Search group at Microsoft.

By default, the program forces unpacking of installation files to the root of the system disk, for example in C:\

I will go into more detail on the description of the operation and some of the settings of this utility a little later, but for now I will show how to create a simple command line script with which you can back up data both manually and automatically, according to a given schedule.

Create a backup script manually.

So, the simplest command that can be used for these purposes using the robocopy utility will look like this:

Robocopy C:\Users\username\Downloads D:\Backup\Downloads

Where C:\Users\username\Downloads is the path to the folder we want to backup, and D:\Backup\Downloads– a directory for its placement.

Create a text file with the extension .txt and copy the command into it. Give the file the name robocopy (any name is possible) with the extension cmd and save. You must run the file as an administrator. Result: the command created a backup copy of the “Downloads” folder in the Backup folder on drive D:

I will provide brief information about some keys that can be used to expand the capabilities of using the robocopy command.

1) To include empty folders in the backup, you need to add a key to the command /E

Robocopy C:\Users\username\Downloads D:\Backup\Downloads /E

2) To exclude hidden system files from copying, use the switch /XA:SH

Robocopy C:\Users\username\Downloads D:\Backup\Downloads /XA:SH

3) The Robocopy utility is capable of processing open files. But when it is detected, the program pauses copying and waits for it to close. Every 30 seconds Robocopy will attempt to resume copying. The default limit for these attempts is one million attempts (!), but who will wait that long? Therefore, the number of attempts should be reduced to a reasonable limit, for example 5-10.

For these purposes, a switch is used /R, and to change the interval between attempts - the switch /W. With the number of attempts to resume copying an open file being 10, and the time interval between them being 15 seconds, the command would look like this:

Robocopy C:\Users\username\Downloads D:\Backup\Downloads /R:10 /W:15

4) To hide the progress of copying each individual file from the screen, you need to add a switch to the command /NP:

Robocopy C:\Users\username\Downloads D:\Backup\Downloads /R:10 /W:15 /NP

5) You can also create a utility report file using the switch /LOG and force it to be overwritten every time you run it again:

Robocopy C:\Users\username\Downloads D:\Backup\Downloads /R:10 /W:15 /NP /LOG:Backup.log

As you can see, this utility has plenty of possibilities, but that’s not all. A complete list of switches for the robocopy command can be found at: http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

Understanding the meaning of each of the keys will allow you to use the functionality of the utility to its fullest. If you don't want to create scripts manually, you can use the graphical interface of the robocopy utility ( Microsoft Robocopy GUI), with the story about which I began this article.

Creating a backup script using the Microsoft Robocopy GUI.

Go to the tab Copy Options(Copy options) and check the necessary checkboxes to add the corresponding switches to the copy script:

Please note that there is a function Save Script(Save script) at the bottom of the window. It allows you to create entire sets of copying scripts, save them in a specified location and use them later as needed:

I checked how this works in practice, and it turned out that saving the script file for example on Desktop impossible:

But saving the file in the default path suggested by the utility occurs without problems:

However, this is not so important - the main thing is that the utility has done its job, a ready-made script file has been created for further use.

Part 2: Running a scheduled backup script.

To schedule a backup to run automatically at a specific time, we need Windows Task Scheduler.

Screenshots clearly demonstrate how to implement this:

1) Create a task and give it a name. Set the “hidden” attribute (which, in principle, is not necessary):

2) In the “Actions” tab, specify the path to the script file:

3) In the “Triggers” tab, assign a scheduled launch:

The basic steps for creating a task have been completed; then, if desired, you can configure the “Parameters” and “Log” tabs.

Save all changes and close Task Scheduler.

As you can see, everything is very simple. Now my “Downloads” folder will be copied to the specified location on drive D according to a schedule (one-time, daily, weekly, etc.).

We use Robocopy. Examples.

- this is an excellent thing, a very flexible tool for copying and even backup. And the most interesting thing is that it supports long file paths i.e. more than 256 characters!!! Wiki: This is a utility for replicating (not just copying) directories (folders). It was available as part of the Windows Resource Kit and is provided as a standard component of Windows Vista, Windows 7 and Windows Server 2008. It is provided by Microsoft "as is" without warranty or technical support.

Designed for fault-tolerant copying of directories and directory trees. It has the ability to copy all (or selected) NTFS attributes and properties, and has additional restart code when used with a network connection in case of a break.

All this is necessary if you need to transfer an entire directory of files from the server with all access rights settings, including file creation time attributes, or copy files excluding some files (by different attributes or extension) or folders. It is also convenient to use robocopy as a program for transferring files from user computers to the server (then incremental archiving works on the server) - the most optimal solution.

Copy optionsfrom robocopy /help

ROBOCOPY:: Robust File Copy for Windows
Usage:: ROBOCOPY source destination [file [file]...] [Options]
Source:: Source folder (drive:\path or \\server\share\path).
Destination:: Destination folder (drive:\path or \\server\share\path).
File:: Copy files (names and wildcards: default "*.*").
::
:: Copy options:
::
/S:: Copy subfolders, except empty ones.
/E:: Copy subfolders, including empty ones.
/LEV:n:: Copy only the top n levels of the source folder tree.
/Z:: Copy files with resume.
/B:: Copy files in archiving mode.
/ZB:: resume mode is used; if access is denied, archiving mode is used.
/EFSRAW:: Copies all encrypted files in EFS RAW mode.
/COPY: copy flags:: what is copied for files (default is /COPY:DAT).
(copy flags: D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner Information, U=Audit Information).
/DCOPY:T:: Copies folder timestamps.
/SEC:: Copy files with security settings (equivalent to /COPY:DATS).
/COPYALL:: Copy all file information (equivalent to /COPY:DATSOU).
/NOCOPY:: Do not copy any file information (useful with the /PURGE option).
/SECFIX:: Fix security settings for all files, even skipped ones.
/TIMFIX:: Fix time attributes for all files, even skipped ones.
/PURGE:: Remove destination files and folders that no longer exist in the source.
/MIR:: Create a mirror of the folder tree (equivalent to /E with /PURGE).
/MOV:: Move files (removing from source after copying).
/MOVE:: Move files and folders (removing from source after copying).
/A+: :: Add specified attributes to copied files.
/A+: :: Remove specified attributes from copied files.
/CREATE:: Create only a folder tree and zero-length files.
/FAT:: Create destination files in 8.3 FAT format only.
/256:: Disable support for long paths (> 256 characters).
/MON:n:: Observe source; restart after n changes.
/MOT:m:: Observe source; restart after m minutes if changes occur.
/RH:hhmm-hhmm:: Startup clock - time when a new copy can be started.
/PF:: Check startup hours by files (not by passes).
/IPG:n:: Interval between packets (ms) to reduce network load on low-speed connections.
/SL:: Copies the symlinks themselves instead of copying the target of those links.
::
:: File selection options:
::
/A:: Copy only files with the “Archive” attribute set.
/M:: Copy only files with the “Archive” attribute and reset it.
/IA: :: Include files that have any of the given attributes set.
/XA: :: Exclude files that have any of the given attributes set.
/XF file [file]... :: Exclude files matching the given names, paths, and wildcards.
/XD dirs [folders]... :: Exclude folders that match the given names and paths.
/XC:: Exclude modified files.
/XN:: Exclude later files.
/XO:: Exclude earlier files.
/XX:: Exclude additional files and folders.
/XL:: Exclude separately located files and folders.
/IS:: Include the same files.
/IT:: Include optimized files.
/MAX:n:: Maximum file size - exclude files larger than n bytes.
/MIN:n:: Minimum file size - exclude files smaller than n bytes.
/MAXAGE:n:: Maximum file age - exclude files older than n days.
/MINAGE:n:: Minimum file age - exclude files less than n days old.
/MAXLAD:n:: Latest last accessed date - exclude files that have not been used since date n.
/MINLAD:n:: Earliest last accessed date - exclude files that were used after date n.
(If n< 1900, то n = n дней, в противном случае n - дата в формате ДДММГГГГ).
/XJ:: exclude junction points. (usually enabled by default).
/FFT:: Use FAT file times (two second precision).
/DST:: Take into account the one-hour difference when switching to daylight saving time.
/XJD:: Exclude junction points for folders.
/XJF:: Exclude junction points for files.
::
:: Retry options:
::
/R:n:: Number of retries for failed copies: default is 1 million.
/W:n:: Timeout between retries: default is 30 seconds.
/REG:: Save /R:n and /W:n in the registry as default settings.
/TBD:: Wait while share names are determined (retry error 67).
::
::Logging options:
::
/L:: List only - files are not copied, deleted, or timestamped.
/X:: Report all additional files, not just selected ones.
/V:: Verbose output indicating missing files.
/TS:: Include timestamps of source files in the output.
/FP:: Include full file paths in the output.
/BYTES:: Print sizes in bytes.
/NS:: No size - do not log file sizes.
/NC:: No class - do not log file classes.
/NFL:: No file list - do not log file names.
/NDL:: Without a folder list - do not log folder names.
/NP:: Without progress - do not display the number of % copied.
/ETA:: Show estimated completion time for file copying.
/LOG:file:: Log status to a log file (overwrite existing log).
/LOG+:file:: Log status to a log file (append to existing log).
/UNILOG:file:: Log status to a Unicode log file (overwrite existing log).
/UNILOG+: file:: Write status to a Unicode log file (append to existing log).
/TEE:: Direct output to the console window and to a log file.
/NJH:: No job title.
/NJS:: No job information.
/UNICODE:: Unicode output status.
::
:: Job parameters:
::
/JOB:job_name:: Take parameters from the specified job file.
/SAVE: job_name:: Save parameters to the specified job file
/QUIT:: Quit after processing the command line (to view options).
/NOSD:: The source folder is not specified.
/NODD:: The destination folder is not specified.
/IF:: Include the following files

Examples of using

All this is done on the command line (Start-Run-CMD) or you can create a bat script.

1. Copy files modified in the last 5 days (excluding today).

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /maxage:5 /minage:1

2. Move all files:
robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /move /e

3. Copy files except hidden ones (/xa:h):

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /e /xa:h

or except read-only (/ia:rs):

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /ia:rs

When copying, you can also change file attributes using the A+ (add attribute) or A- (remove attribute) option. Copy all files and give them the read-only attribute:

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /e /A+:r

4. Copy all files using the template (extension), do not copy empty folders:

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" *.doc *.ppt /s

5. Copy all files ranging in size from 1000 to 60000 bytes:

robocopy "E:\Documents" "\\NAS\BACKUP\Documents" /e /max:60000 /min:1000

6. Exclude the AppData folder (/XD AppData) from copying:

Robocopy "C:\Users\Administrator" "\\NAS\BACKUP\Administrator" /MIR /XA:SH /XD AppData /XJD

7. Create 32 threads (/MT:32) copying files:

Robocopy "C:\Users\Administrator" \\NAS\BACKUP\Administrator /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32

8. Copy files from one folder to another with standard attributes, excluding the file extension (for example *.doc)

Robocopy » Robocopy “C:\Users\Administrator” “\\server\userbackup” /СOPY:DAT /XF *.doc

Example of use for backup

1)

robocopy D:\source_folder\\192.168.0.1\destination_folder /E /Z /COPY:TDASO ​​/DCOPY:T /M /R:2 /W:5 /MT:64

In this example:
We copy the "source folder" folder located on the local drive D:
We copy this folder to the computer \\192.168.0.1 in the "target folder" folder
/E: We copy all subfolders and files
/Z: Enable resuming support (in case the connection is lost)
/COPY:TDASO: Copy all NTFS permissions attributes and ACLs (but do not copy audit attributes)
/DCOPY:T: Copy folder creation time
/M: Copy only files with the “A - Archive” attribute set and reset this attribute, which allows us to copy only modified files.
/R: The number of times to retry copying a file if copying fails. Moreover, “failed” also works if access to the file is denied. Default = 1 million, i.e. infinitely, because copying will happily stop at the very first file to which there will be no access.
/W: Delay in seconds between copy attempts. Default = 30 seconds.

/MT - number of threads, increasing which can speed up copying. It will be faster than regular file copying for sure.

2) A similar example, but note that each time the backup is copied to a folder named date and time. Very convenient for creating additional backups.
robocopy D:\source_folder\\192.168.0.1\target_folder\ %date:~0.2%.%date:~3.2%.%date:~6.4%.%time:~0.2%-%time:~3.2% /E /Z /COPY:TDASO ​​/DCOPY:T /M /R:2 /W:5


%date:~0.2%.%date:~3.2%.%date:~6.4%.%time:~0.2%-%time:~3.2% - date and time created Setting the backup as a folder name. The result is a folder like 16.01.2016-10.19

Or like this - %date:~6.4%-%date:~3.2%-%date:~0.2%_%time:~0.2%-%time:~3.2% Result - 2016 -03-13_23-30

You can also find out a lot of interesting things by typing the command set /?

Date format on the command line:

@echo off set day=%DATE:~0.2% set month=%DATE:~3.2% set year=%DATE:~6.4% set hour=%TIME:~0.2% set minute= %TIME:~3.2% set second=%TIME:~6.2% echo %day% echo %month% echo %year% echo %hour% echo %minute% echo %second% set YYYYMMDD=%year%% month%%day% echo %YYYYMMDD%

And Windows Server 2008. Robocopy functionally replaces Xcopy, with more options.

Robocopy
Type Microsoft Windows component [d]
Developer Microsoft
operating system Windows NT, Windows 2000, Windows XP, Windows 2003, Windows Vista, Windows 7, Windows Server 2008.
Latest version 10.0.17763.1
License Proprietary software
robocopy C:\A \\backupserver /E /MAX:102400000 /MIN:102400

Copy specific formats, such as avi:

Robocopy C:\A \\backupserver *.exe *.avi /S

A complete list of commands is available on the Microsoft TechNet page - Robocopy

GUI

Robocopy is a command line utility, so for ease of use, Microsoft Technet provides a graphical shell for it (GUI front-end), authored by Derk Benisch. The wrapper requires the .NET Framework 2.0.

Bandwidth Management

Robocopy has an "inter-packet gap (IPG)" option that allows you to control the network bandwidth used in the session. In theory, the following formula expresses the latency (D, in milliseconds) required to simulate the desired bandwidth (BD, in kilobits per second) over a network with available bandwidth BA kbps:

D = B A − B D B A × B D × 512 × 1000 (\displaystyle D=(B_(A)-B_(D) \over B_(A)\times B_(D))\times 512\times 1000)

In practice, you usually have to experiment to find a suitable delay due to factors such as the nature and volume of traffic on the network. The methodology used by the IPG option may not provide the same level of control provided by some other bandwidth throttling technologies, such as BITS (which is used by Windows Update and BranchCache).

Every Wintel administrator is familiar with the Robocopy utility. Since the days of Windows NT4, it has been included in the Resource Kit, and since Windows Vista, it has been part of the operating system.
Why is Robocopy needed? To copy files. Lots of files. We mainly use it for file server migration or backup.
There are many interesting options for migrating file servers, for example using DFS-R. But there is nothing simpler and more reliable than launching

Robocopy \\SERV\D$ F:\ /e /copyall /zb /mt:8 /r:1 /W:5 /V /TS /FP /ETA /TEE /LOG:c:\temp\robocopy.txt

Finally, you can close user access to the resource and create an incremental copy by adding the /MIR key.
But is Robocopy so good?? Is she good enough to trust her to migrate your most important files?

One fine Saturday afternoon I migrated a file server. There were no employees at work. The first copy was made yesterday, all that remained was to make an increment and update the links in DFS.
I launched Robocopy, looked at the log, and to be on the safe side, before switching, I decided to look at how many files and folders were in the source and destination file share. The numbers didn't add up. Suddenly.

But why? This is the first time I have seen such a result. Did I do something wrong? Did any of the employees change the files while the incremental copying was going on? Has the /MIR key failed? Are any files missing? Empty? With Access Denied? Damaged?

Okay, let's turn off network access and copy the files again. Doesn't add up! Let's try without /MIR. Same result.
I was at a loss. For fifteen years I trusted Robocopy 100%, and today, for the first time, it failed. Some files simply aren't in the destination! It's simply impossible to believe it.

Let's count files differently. Download the FileList utility and list the files in the source and destination folders. But here the number of files coincided. Marvelous.

What if it's not Robocopy? What if Windows Explorer doesn't count correctly? Maybe Windows Server 2008 R2 has a bad Explorer, but Windows Server 2012 R2 has a good one? I opened the local and target folder properties on the Windows Server 2008 R2 source server. The number of files did not match. Let's hope everything is fixed in Windows Server 2012 R2. We open the properties of folders on the new server... And...

Not only the number of files in the source and destination folders did not match. The number of files differed from those captured on Windows Server 2008 R2. Black street magic.

And at that moment (finally) an epiphany came to me. It's not about Robocopy, and not about Explorer versions. Explorer simply cannot (!) count, and does not count files and folders with names longer than 260 characters.

On the original server, the files were located along the path “F:\Office1”. On the new one - “U:\SharedFiles\Office1”.
Just because of the “SharedFiles” subfolder, some file and folder names became longer than 255 characters. It was not difficult for Robocopy to copy them. FileList counted them easily. And only Explorer missed such files when counting.

Having made subst N: U:\SharedFiles and counted the number of files in F:\Office1 on the source server and N:\Office1 on the target server, the number of files coincided.

Robocopy can be trusted.

UPD: As correctly corrected in the comments, it’s still not 255, but

Robocopy (Robust File Copy) is a command line utility that comes with Windows Vista and newer versions of Windows. In older versions of Windows, it was part of the Windows Resource Kit Tools. Unlike the regular copy command, Robocopy is designed to make copying and mirroring more reliable. With support for resolutions, attributes, user information, timestamps of copied objects.

Robocopy syntax:

robocopy source destination
  • source - the directory from which we will copy. Could be a network path.
  • destination - directory where we copy. Local or network path.
  • - files that need to be copied. Wildcard characters (* or ?) can be used. If the parameter is not specified, *.* is used by default

Examples of using the Robocopy command

robocopy c:\src c:\dst *.txt

This example will copy all .txt files from the c:\src directory to the c:\dst directory.

Robocopy c:\src c:\dst /e

Copy all files, including empty ones.

Robocopy c:\src c:\dst /MIR

Will make a mirror. Use with caution as from c:\dst all files that are not in c:\src will be deleted

Robocopy robocopy \\computer\src c:\dst

The source of the files is on another computer on the network.

Description of all options and parameters

Robocopy copy options

Description

/s Copy subdirectories. Empty directories are skipped.
/e Copy subdirectories, including empty ones.
/lev: Copy top ones only N directory tree levels.
/z Copy files in restart mode.
/b Copy files in Backup mode.
/zb Restart mode is used. If access is denied, then Backup mode is used.
/efsraw

Copy encrypted files in EFS RAW mode.

/copy:

Specify which file properties will be copied. The correct options for this option are:

  • D Data
  • A Attributes
  • T Time stamps
  • S NTFS access control list (ACL)
  • About Owner information
  • U Auditing information

The default value is DAT (data, attributes, and time stamps).

/dcopy:T Copy directory timestamps.
/sec Copy files with security (equivalent to /copy:DAT).
/copyall Copy all file information (equivalent to /copy:DATSOU).
/nocopy Do not copy information across files (useful with the /purge option).
/secfix Fix security on all files, even skipped ones.
/timfix Record the time on all files, even skipped ones.
/purge Delete files in the destination folder that are no longer in the source folder.
/mir Mirror the directory tree (equivalent to two /e options plus /purge).
/mov Move files. Those. after copying, the original ones will be deleted.
/move Move files and directories. The sources will be deleted.
/a+: Add attributes to copied files. Adds the specified attributes to copied files.
/a-: Remove attributes from copied files.
/create Create a directory tree and zero-sized files.
/fat Create files with names in 8.3 format as in FAT.
/256 Disable support for very long paths (those greater than 256 characters).
/mon: Monitors the source folder and if it detects more than N changes, it will start copying the changed files. Read more here: scheduler in Robocopy.
/mot: Monitors the source folder, looking for changes every M minutes and starts copying if there have been changes. Read more here: scheduler in Robocopy.
/rh:hhmm-hhmm Specifies the time at which the scheduled copy will begin. Read more here: scheduler in Robocopy.
/pf Checks run times on a per-file (not per-pass) basis.
/ipg:n Specifies the inter-packet gap to free bandwidth on slow lines.
/sl Copy symbolic links instead of the actual file.

File selection options

/a Copy only those files that have an archive attribute.
/m Copy only those files that have an archive attribute, and then reset this attribute.
/ia: Copy only those files that have the specified attributes.
/xa: Do not copy files that have the specified attributes.
/xf [ ...]

Do not copy files whose name or path is similar to the specified one. You can use "*" and "?" in the file name.

/xd [ ...] Do not copy directories whose name or path is similar to the given one. You can use "*" and "?" in the directory name.
/xct Do not copy modified files.
/xn Do not copy new files.
/xo Do not copy old files.
/xx Do not copy files and folders that are already in the destination folder.
/xl Excludes "lonely" files and directories.
/is Includes the same files.
/it Includes "tweaked" files.
/max: Do not copy files larger than N byte.
/min: Do not copy files whose size is less than N byte.
/maxage: Do not copy files that are older N days.
/minage: Minimum file age N days.
/maxlad: Do not copy files that have not been used since the date N.
/minlad: Copy files that were used before a certain date. If N less than 1900, then these are days. Otherwise it is the year in the format YYYYMMDD.
/xj Do not copy junction points. By default they are copied.
/fft Assumes FAT file times (two-second precision).
/dst Compensates for one-hour DST time differences.
/xjd Do not copy junction points for directories.
/xjf Do not copy junction points for files.

Replay options

Log options

/l It will show a list of files that are selected for processing, but the actual copying, deletion, etc. will not be executed.
/x Reports all additional files, not just those that are selected.
/v Chatty mode. Will also show missing files.
/ts

Shows file timestamps.

/fp Show full paths to files.
/bytes Show file size in bytes.
/ns Specifies that file sizes are not logged.
/nc Specifies that file classes should not be logged.
/nfl File names will not be logged.
/ndl Directory names will not be logged.
/np Copy progress will not be shown. Those. number of files and directories.
/eta Shows the estimated arrival time of copied files.
/log: Log to file. If such a log file already exists, it will be overwritten.
/log+: Log to file. If such a log file already exists, the data will be added to it.
/unicode Display status in Unicode.
/unilog: Log to a file in Unicode format. If such a log file already exists, it will be overwritten.
/unilog+: Log to a file in Unicode format. If such a log file already exists, the data will be added to it.
/tee Log both to a file and to the console.
/njh Indicates that there is no job title.
/njs Indicates that there is no job summary available.