Robocopy.exe Use Detail Example

Source: Internet
Author: User
Tags ntfs permissions robocopy

Robocopy.exe is a program provided by Microsoft in Windows Server 2003 Resource Kit Tools to make a backup. Vista,win2008 has already brought it.
There are some limitations to the traditional "copy and paste" functionality built into Microsoft Windows. It does a good job of performing simple tasks (moving a document from one directory to another), but lacks the advanced features that IT professionals need in the workplace. For example, copy and paste operations do not include any advanced resiliency features, so recovery from a brief network outage is not allowed. Especially when copying a complete directory, it is still an all-or-nothing problem. With the UI, you cannot choose to copy only new files or to copy the updated files. You can copy individual files, the entire directory, or nothing.
Starting Robocopy, this powerful tool is included in Microsoft Windows Server 2003 Resource Kit Tools, taking into account all of these advanced features and more. Robocopy supports more important file replication tasks, which can really simplify your work. I think you will find that the biggest benefit is that you can create two file structures (which can include all subfolders and files depending on your selection) without copying any unwanted files. Only new or updated files in the source location are copied. Robocopy also allows you to keep all relevant file information, including date and time stamps, secure access control lists (ACLs), and more.


----------------"Parameters"-------------------
Robocopy/?
-------------------------------------------------------------------------------
ROBOCOPY:: Reliable File replication for Windows
-------------------------------------------------------------------------------
Start time: Fri May 08 17:10:13 2009
Usage:: ROBOCOPY source destination [file [file] ...] [Options]
Source:: Source directory (drive: \ path or \ \ server \ share \ Path).
Directory:: Destination directory (drive: \ path or \ \ server \ share \ Path).
File:: File to copy (name/wildcard: "* *" by default).
::
:: Copy options:
::
/S:: Copy subdirectories, but empty subdirectories are not copied.
/e:: Copy subdirectories, including empty subdirectories.
/lev:n:: Copies only the first n tiers of the source tree.
/z:: Copy files in restartable mode.
/b:: Copy files in Backup mode.
/ZB:: Use the restart mode, or use Backup mode if Access is denied.
/efsraw:: Copy all encrypted files in EFS RAW mode.
/copy: Copy tag:: The contents of the file to be copied (default is/copy:dat).
(Copy tag: d= data, a= attribute, t= timestamp).
(s= security =ntfs acl,o= owner information, u= Audit information).
/dcopy:t:: Copy the directory timestamp.
/sec:: Copy files with security (equivalent to/copy:dats).
/copyall:: Copy all file information (equivalent to/copy:datsou).
/nocopy:: Do not copy any file information (in effect with/purge).
/secfix:: Fix file security for all files, even skipped files.
/timfix:: Fixed file time for all files, even skipped files.
/purge:: Delete target files/directories that no longer exist in the source.
/mir:: Mirrored directory tree (equivalent to/E and/purge).
/mov:: Move the file (deleted from the source after copying).
/move:: Move files and directories (deleted from source after copying).
/a+:[rashcnet]:: Adds the given property to the copied file.
/a-:[rashcnet]:: Removes the given property from the copied file.
/create:: Only create a directory tree and zero-length files.
/fat:: Only use 8.3 FAT file name to create the target file.
/256:: Turn off Long path (> 256 character) support.
/MON:N:: Monitor source, run again when more than n changes are found.
/MOT:M:: Monitor source, if changed, run again within M minutes.
/RH:HHMM-HHMM:: Run hours-the time at which a new copy can be started.
/PF:: Checks the number of running hours on a per-file basis, rather than on each step.
/IPG:N:: Space between packages (MS) to release bandwidth on low-speed lines.
/SL:: Copy the symbolic link against the target.
::
:: File Selection options:
::
/A: Copy only files that have an archive attribute set.
/M:: Copy only files with archive properties and reset archive properties.
/ia:[rashcneto]:: Contains only files with any given set of properties.
/xa:[rashcneto]:: Excludes files with any given set of properties.
/XF file [file] ...:: Excludes files that match the given name/path/wildcard character.
/XD directory [Directory] ...:: Excludes directories that match the given name/path.
/XC:: Excludes files that have changed.
/XN:: Exclude newer files.
/xo:: Exclude older files.
/XX:: Exclude redundant files and directories.
/XL:: Exclude orphaned files and directories.
/IS:: Contains the same file.
/it:: Contains the adjusted file.
/max:n:: Maximum file size-excludes files larger than n bytes.
/min:n:: Minimum file size-excludes files less than n bytes.
/maxage:n:: Longest file existence time-excludes files older than n days/dates.
/minage:n:: Shortest file existence time-exclude files that are later than n days/date.
/maxlad:n:: Maximum last access date-files that have not been used since n are excluded.
/minlad:n:: Minimum last access date-Files used since n are excluded.
(If N < 1900 then n = n days, Else n = YYYYMMDD date).
/XJ:: Exclude junction points. (usually included by default).
/fft:: Suppose FAT file time (2 second granularity).
/DST:: Compensate for the 1-hour DST time difference.
/XJD:: Exclude the junction of the directory.
/XJF:: Exclude the junction point of the file.
::
:: Retry Options:
::
/R:N:: Number of retries for failed replicas: default is 1 million.
/w:n:: Two wait time between retries: default is 30 seconds.
/reg:: Save/r:n and/w:n in the registry as the default settings.
/TBD:: Wait to define the share name (retry error 67).
::
:: Logging options:
::
/L:: List only-do not copy, add timestamp, or delete any files.
/x:: Report all the extra files, not just the selected files.
/V:: Generates verbose output while displaying skipped files.
/ts:: Contains the timestamp of the source file in the output.
/FP:: Contains the full path name of the file in the output.
/bytes:: Print size in bytes.
/ns:: No Size-no file size is recorded.
/NC:: No category-the file category is not recorded.
/NFL:: No file List-the file name is not recorded.
/ndl:: No directory List-no record directory name.
/NP:: No progress-the percentage that has been copied is not displayed.
/eta:: Displays the expected arrival time of the copied file.
/log: File:: Outputs the status to the log file (overwriting the existing log).
/log+: File:: Outputs the status to the log file (attached to the existing log).
/unilog: File:: Outputs the status to a log file (overwriting an existing log) in UNICODE mode.
/unilog+: File:: Outputs the status to a log file (attached to an existing log) in UNICODE mode.
/tee:: Output to console window and log file.
/NJH:: No job header.
/NJS:: No Job summary.
/unicode:: Outputs the state in UNICODE mode.
::
:: Job Options:
::
/job: Job Name:: Extract the parameters from the named job file.
/save: Job Name:: Saving parameters to a named job file
/quit:: Exit after processing command line (to view parameters).
/NOSD:: The source directory is not specified.
/nodd:: Destination directory not specified.
/if:: Contains the following files.
----------------"Example"-------------------
Example one: file, how to copy on how to copy
[Implementation effect]
The plain Text (TXT), Word document (DOC), and BMP, TIF image files in the source folder are copied to the destination folder at any time, which is not available for direct drag and drop in the explorer.
[Simple command]
Robocopy d:\work e:\back *.txt *.doc *.bmp *.tif/s
[Parameter explanation]
The TXT, DOC, BMP, TIF files under the D:\work file are copied to the E:\back folder, and the other files are not copied. /S is a representation of all subdirectories, including all except empty files, if not only the files under D:\work are copied, not subdirectories.
Extrapolate
(1) If you want to copy all files under the folder including empty folders to the destination folder, the command is: Robocopy d:\work e:\back/e
/e means that all subdirectories are copied including empty folders.
(2) If you want to copy only two levels of the file (the next level of the file is not copied), enter the command: Robocopy d:\work e:\back/e/lev:2
/lev:2 represents the level of replication, such as the D:\work\soft (level two) file is copied after the specified level, and files under d:\work\soft\office (* * *) are not copied.
Example two: Junk files are not copied
[Implementation effect] when backing up data, it is inevitable that similar to *.bak, *.tmp garbage files are also copied to the target folder, with the Robocopy can be used to remove the junk files we frequently encountered in the copy of the House, so as to generate a clean folder.
[Simple command]
Robocopy d:\work e:\back/e/xf *.tmp *.bak
[Parameter explanation]
/XF to specify a file type that does not perform a copy operation, the following file name supports wildcard characters. If the parameter is/XD, the folder specified later is excluded.
Example three: Large file I don't want to
[Implementation effect]
When copying, in order to save time, some large files need to be temporarily not copied, and so on when there is idle time, and then perform the copy operation is not too late.
[Simple command]
Robocopy d:\work e:\back/e/max:6000000
[Parameter explanation]
Only copy files less than 6000000bytes,/max: Directly after the value, the value unit is byte. If it is/min:1000, copy files of no less than 1000bytes. Two parameters can be used at the same time to define the scope of the copied file size.
Example four: As long as the files modified this week
[Implementation effect]
What documents are processed this week? Did you edit those files? Copy these modified documents to a folder and have a good aftertaste. This example is to copy the new or modified TXT, DOC, XLS, PPT, and other documents in d:\work within the last seven days to the E:\look directory.
[Simple command]
Robocopy d:\work e:\look/s *.txt *.doc *.xls *.ppt/maxage:7
[Parameter explanation]
/maxage: Represents the furthest modification time, and the modified time is older than this file will not be copied. /maxage: After the number can be connected to the date, the number is less than 1900 to indicate the number of days, otherwise you have to use YYYYMMDD to represent the specific date, such as/maxage:20040210 that the modified file after February 10, 2004 is allowed to replicate. The corresponding parameter is/minage, which represents the last modification time, and the new file will not be copied at this time.
Extrapolate
Robocopy d:\work e:\look/s *.txt *.doc *.xls *.ppt/maxage:7/minage:1
It means that files modified in the last seven days except today are allowed to be copied.
Compared to the modified time, the last access time,/maxage refers to the furthest access time, older than this time the file will not be copied. /minage refers to the most recent access time, and new files will not be copied at this time.
Example five: My document Platoon station
[Implementation effect]
When you copy in the example above, all the documents will have their own path information, and the document will copy the folders they are stored in. This has brought us a lot of inconvenience, we have to click the multi-level folder to see the file, can you copy all the documents directly into a folder? This needs to be implemented with Xxcopy.
[Simple command]
Xxcopy d:\work e:\look/s/in*.txt/in*.doc/sg/yy/da:2004-02-02/db:2004-02-10/da:1997-01-01
[Parameter explanation]
This command copies the TXT, doc files generated from the d:\work from February 2, 2004 to February 10 directly into the E:\look directory without creating a new subfolder, opening E:\look to see all the files. The syntax parameters of Xxcopy and robocopy are still significantly different, indicating that when a file type is specified, xxcopy will use/in*.*, representing the date/da at the specified time, and/db as the date before the specified time.
In addition,/SG indicates that the file is copied to the same folder, and/yy indicates that it is automatically considered yes in all areas where the user is required to answer, and that no user intervention is required during execution.
Example six: Full cloning
[Implementation effect]
We generally take the replication method by default is incremental replication, that is, according to the size of the file, modify the content of the source folder to the target folder, over time, there may be a large number of folders in the source folder has been deleted and useless files and folders. If you want to make the backup exactly the same, delete the files that exist in the destination folder but not in the source folder when you copy.
[Simple command]
Robcopy d:\work E:\look/mir
[Parameter explanation]
The role of/mir is equivalent to/purge/e,/purge, which indicates that files (folders) that are not in the source folder are cleaned up. With this command, the source and destination folder structures are guaranteed to be identical to the file. This is useful when creating a mirrored backup.
Example seven: Moving files
[Implementation effect]
What we're talking about is copying, and if we're going to move the folder to the target folder, how do we do it?
[Simple command]
Robocopy D:\work e:\look/move/e
[Parameter explanation]
Where/move represents the move.
Example eight: I just need a folder skeleton
[Implementation effect]
The author's work needs to create and organize a large number of folders periodically, each time the folder structure, but the file is not the same. If it was before, it would have to be a simple repetition of the production, and now it is not necessary. Robocopy and xxcopy allow you to easily replicate folder structures.
[Simple command]
Xxcopy d:\work e:\mystruct/t/yy/dl3
[Parameter explanation]
Copy the D:\work three-tier folder structure to E:\mystruct.  where/t means the folder structure is created,/DL3 indicates that the folder structure of the replication is * * *, the numbers can be entered by themselves, and if not, the entire folder structure is established by default. Robocopy Creating a folder is a bit cumbersome,/create parameter not only to create the structure, but also to create a folder of all files under the 0-byte file, not the real structure, we had to go pifo the sword.
Robocopy d:\work e:\mystruct/e/lev:3/minage:19000101
Specify a time for Robocopy to be unable to create the file, because there is the function of the parameter/E, although there is no file to meet the requirements (you do not have files earlier than January 1, 1900), but Robocopy will still be faithful to create the folder, so that the purpose of generating folder structure. In addition,/lev:3 represents the level of the replicated folder, which can also be entered on its own.
Example nine: Hidden files I don't want to
[Implementation effect]
By default, hidden files are not displayed, but during replication, they are also copied along with the folder. Can these hidden files be excluded from the replication scope?
[Simple command]
Robocopy d:\work e:\back/e/xa:h
[Parameter explanation]
Robocopy supports manipulation of attributes. The above command will copy all the files in the source folder, but all files with hidden properties will not be copied. /xa:h, which represents the exclusion of a replication scope with a hidden property, corresponds to a/ia, which means that only the execution of the property that owns the specified attribute is included. The properties are r: Read-only, A: archive, S: System, H: Hidden, and several other options.
Extrapolate
(1) In addition, Robocopy also have/a+,/a-and other parameters to manipulate the file attributes, respectively, after the file is copied to the file to add, remove a property.
Robocopy D:\work E:\back/ia:rs
Indicates that only files with read-only and system properties are copied.
(2) Robocopy c:d:/-a:rsh
After copying files to the D drive, the read-only, system, and hidden properties of the copied generated files are removed for easy viewing and modification.
Example ten: NTFS permissions follow along
[Implementation effect]
When using Windows 2000, Windows XP, when multiple users use a single computer or when managing a server, it is often necessary to specify permissions for the folder for users to access and modify (1, which requires partitioning to NTFS). However, the permissions we set are not preserved with normal replication, which means that we have to reset the user permissions when the server is backed up. However, Robocopy allows us to copy files to the target folder by copying the properties, user rights, and owner.

Backup two neighbors wonderful 5 cases-robocopy and xxcopy full Mastery
[Simple command]
Robocopy d:\work e:\back/e/copyall
[Parameter explanation]
/copyall equals/copy:datsou, which means that all source folder information is copied to the destination folder, where D: File data, A: File properties, T: Time information, S: Permission information, O: Owner information, U: Audit information.
Extrapolate
If the permissions of the source folder are modified and you need to update the permissions of the target folder as well, we do not have to repeat the copy, just enter Robocopy d:\work E:\back/is/copy:sou If there is no/copy parameter, the default is/copy:dat, There is no information for the following three items.
Example 11: Centrally backing up to a file server
[Implementation effect]
You want to be able to back up the data to a file server every day to avoid data loss.
[Simple command]
Robocopy d:\work \ctips_serverarticlesshare/e/copyall
[Parameter explanation]
As you can see, Robocopy fully supports copy of File server shared folder data.
Extrapolate
(1) If we create an environment variable, such as defining%databack% as \ctips_serverarticles\back, then just enter the appropriate command: Robocopy d:\work%databack%/e/copyall can d:\ All files under work are backed up to \ctips_serverarticles\back. Of course, if the \ctips_serverarticles\back space is not enough, simply change the value of the environment variable to another folder, such as \ctips_serverarticles Ewback, the above command can copy the data to the new folder without changing it.
(2) If you only want to back up the data to a shared folder in a shared folder named after your machine name, it is more convenient to use xxcopy: Xxcopy d:\work \ctips_serverarticles/$HOST $/e/yy where/$HOST $ Indicates your machine name, such as your machine name Ctips_syj, that will copy the files under the D:\work folder to the \ctips_serverarticles\ctips_syj folder. If your machine name is CTIPS_MLB, then you can copy the files under the D:\work folder to the \CTIPS_SERVERARTICLES\CTIPS_MLB folder after executing the above command. Since the name of the machine in the LAN is not the same, the execution of the above command will ensure that the data will not be copied to the same folder.
Example 12:1 moving on backup
[Implementation effect]
Some of the work content is very important, need to pay attention to the backup, but where do we have such a good memory and patience? Let the Robocopy do it. Robocopy can always monitor the folder to be backed up, as long as the folder is modified to a certain time and program, Robocopy will start the backup immediately. It will always monitor the folder unless the user terminates it himself.
[Simple command]
Robocopy d:\work e:\back/e/copyall/mot:1/mon:2
[Parameter explanation]
The above command indicates that all the information in the folder is copied to the destination folder and monitored. After you execute this command, the command prompt is shown in window 2. Once the time has past one minute and the source folder has at least 2 or more modifications, Robocopy will automatically start another process to perform the above backup operation. Robocopy can monitor the source folder structure, file and folder name, size, and last modified time, where even when information such as properties and permissions are modified, Robocopy is also remembered as the number of changes. Backup two neighbors wonderful 5 cases-robocopy and xxcopy full Mastery
/mot followed by the time (minutes), refers to the robocopy the shortest time to perform the operation,/mon followed by the minimum number of file modifications. During the monitoring process, the time and the number of modifications are automatically recorded, and Robocopy begins execution only when the above two conditions are met, and after execution completes, the two data are automatically zeroed and the Monitoring folder is restarted until the user closes the command prompt window or presses the Ctrl+break key.
Extrapolate
If you want to monitor and back up the appropriate folder when you turn it on, you can put the above command in the Startup group.
Example 13: Less time not backed up
[Implementation effect]
The process of copying always consumes system resources, and it is much more convenient to start copying backups when you are not on the edge of your computer. For example, 5:50 every day, hope after work, arrive 6 o'clock, Robocopy automatically start to back up the corresponding data.
[Simple command]
Robocopy d:\work e:\back/e/rh:1800-1830
Extrapolate
After running, the copy operation will wait until the specified time starts (3). Where the RH format is/RH:HHMM-HHMM, specifying the time period at which the Robocopy begins, the copy will be paused outside of this time period. The time is 24-hour format, 4 digits long, from 0000 to 2359, and two numbers cannot be the same. Backup two neighbors wonderful 5 cases-robocopy and xxcopy full Mastery
Example 14: Scheduled Task backup
The above to time backup, monitor folder backup method, each reboot system will have to re-execute the above command, is far from smart enough, if you can and Windows's scheduled tasks, all the problems will be solved. As an example, we want to automatically call Robocopy at 10:00 every day to start monitoring the backup folder, saying that the scheduled tasks work with Robocopy.
First step: Create a new BAT file autobak.bat a batch file, enter the following command robocopy d:\work e:\back/e/copyall/mot:1/mon:2
Step Two: Create a scheduled task select Start → settings → control Panel, and double-click the Task Scheduler icon. Drag and drop the Autobak.bat batch file into the Task Scheduler window, and then double-click the newly generated Autobak.bat icon to set its properties in the pop-up window.
Step three: Set the start time to switch to the Schedule tab, click the Scheduled Task drop-down list box, select Daily, start time set to 10:00, and click Advanced to set the ending Date (4).
With the above settings, the machine automatically backs up and monitors folders automatically when the time is set to run the batch file. Backup two neighbors wonderful 5 cases-robocopy and xxcopy full Mastery
Example 15: Clean files are also good
In addition to the general replication functionality, Xxcopy also has the File Cleanup feature, which allows you to quickly clean up your hard disk with unwanted files. The following command clears the files and folders, first establish a test folder and then manipulate the folders before you know what to do.
1. Clear all useless files
Xxcopy d:\work*.tmp/s/h/yy/rs
/RS indicates that the specified file is deleted directly from the source folder without copying, and/h indicates the hidden and system files are specified.
2. Clear the folder
Xxcopy C:emp/rmdir/db:2002-01-01/yy
Delete the C:emp folder that was modified before January 1, 2002.
3. Delete Empty folders
Xxcopy c:emp/rmdir/sz:0/yy
Delete all empty folders under C:emp,/sz:0 specify a file size of 0 (clip).
4. Delete a 0-byte file
Xxcopy c:emp*.*/sz:0/s/h/yy/rs
With the combination of the above four ways, we can easily organize the files and folders.
Finally, there are a few tips to tell you that hopefully it will help you to better use Xxcopy and Robocopy.
★ Turn command into task in Robocopy Plus "/save: Task Name" can record the current operation as a task file, through the "/job: Task Name" can be easily called, no need to enter a long list of commands. This task file can be edited with a plain text editor, such as Notepad.
★ Record the copy backup process by default, the Robocopy process is displayed only at the command prompt, and we can let it output the operation process as a TXT file, plus "/log: TXT".

Robocopy.exe Use Detail Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.