2. Use of Windows Server-Robocopy

Source: Internet
Author: User
Tags ntfs permissions robocopy

The functionality of the copy operation provided by Windows is simply too crude to be customizable and is not strong enough to replicate, move, and back up folders with multiple cycles of operation. Now we're going to introduce you to two powerful copy backup software: Robocopy and xxcopy, how does it work? There's no need to say it, but the following examples will make you like them.

Robocopy Small File

Software version: XP010 software size: 80KB

Software Nature: Free software application Platform: Windows 9x/me/nt/2000/xp

: http://www.baiduns.com/bencandy.php?fid=56&id=592


Example one: file, how to copy on how to copy

[Implementation] At any time, the source folder in plain text (TXT), Word documents (DOC) and BMP, TIF image files are copied to the destination folder, which is not directly in the Explorer to drag and drop can not be done. [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 D:/work/soft (Level two) after a specified level, and files under D:/work/soft/office (level three) 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

When the [implementation effect] is copied, 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? Edit those files? Copy the modified documents to a folder, and then take a good look. 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 a 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] In the previous example, when copying, all documents will bring their own path information, the document will be stored in the folder also copied over. 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 done 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.

[NextPage]

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, the target folder may exist in a large number of source folders have 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] we are talking about replication, if we want to move the folder to the target folder, how to 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 periodically create and organize a large number of folders, each time the folder structure, just the files are different. 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 level three, the numbers can be entered by themselves, and the entire folder structure is established by default without this parameter.

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] The hidden file is not displayed by default, but it is also copied along with the folder during the copy process. 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 are using a computer or managing a server, you often specify the permissions that users access and modify for the folder (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.


[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 replication, just enter

Robocopy D:/work E:/back/is/copy:sou

If there is no/copy parameter, the default is/copy:dat, and there is no information for the following three items.

[NextPage]

Example 11: Centrally backing up to a file server

[Implementation] you want to be able to back up the data to the file server every day to avoid data loss.

[Simple command]

Robocopy d:/work//yesky_server/articles/share/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//yesky_server/articles/back, then just enter the appropriate command: Robocopy d:/work%databack%/e/copyall can put D : All files under/work are backed up to//yesky_server/articles/back. Of course, if//yesky_server/articles/back space is not enough, just change the value of the environment variable to another folder, such as//yesky_server/articles/newback, The above commands can be copied to a new folder without any changes to the data.

(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//yesky_server/articles//$HOST $/e/yy where/$HOST $ Indicates your machine name, such as your machine name Yesky_syj, that will copy the files under the D:/work folder to the//yesky_server/articles/yesky_syj folder. If your machine name is YESKY_MLB, then you can copy the files under the D:/work folder to the//YESKY_SERVER/ARTICLES/YESKY_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] Some of the work content is very important, need to pay attention to the backup, but where we have such a good memory and patience? This matter, or give robocopy to 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.


/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 replication always consumes system resources, it is much easier 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.


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

Create a new batch file Autobak.bat, 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

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 starting and 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.

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:/temp/rmdir/db:2002-01-01/yy

Delete the C:/temp folder that was modified before January 1, 2002.

3. Delete Empty folders

Xxcopy c:/temp/rmdir/sz:0/yy

Delete all empty folders under C:/temp,/sz:0 specify a file size of 0 (clip).

4. Delete a 0-byte file

Xxcopy c:/temp/*.*/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 a task

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 only displayed at the command prompt, and we can let it output the process as a TXT file, plus "/log:. txt".

Reference: http://blog.csdn.net/mutougede/article/details/5691765

This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1642100

2. Use of Windows Server-Robocopy

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.