Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Robocopy command to realize daily mirror backup / incremental backup operation of file server

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Robocopy is a reliable file replication service launched by Microsoft, which has been tested to be better than xcopy, especially in copying ACL and file timestamps.

Free synchronization software is usually weak in ACL synchronization, while paid software is complex, so we can use robocopy combined with task program to do daily backup and incremental backup.

Tips:

/ dcopy:T can copy directory timestamps.

If not, the folder time is the point in time at which replication occurs. If you want the timestamp and the source directory to be constant, you can execute the command again and add / dcopy:T.

/ log: log

Add the / tee command when you run the test, so that you can

/ log+, continue to write to the same log.

Note: only / dcopy:T is supported in windows7 or windows2008R2 / dcopy

Mirror synchronization Left > Right

Robocopy "c:\ abc"D:\ abc" / mir / copyall / dcopy:DAT / mt:8 / z / xa:sht / Amuri Vista h / np / ts / WRV 1 / XD "System Volume Information" / XD $RECYCLE.BIN / aRue H / log:H:\ Log\ Robocopy\ RBLog.txt / tee

The effect is to synchronize the abc folder of disk C (including all the attributes of abc itself) into the ABC folder of disk D (disk D can not have an abc folder, it will be created automatically, and if it already exists, it will overwrite the ACL of abc), including all files & folders within abc, including all ACL and file attributes, including all file creation, access, and modification time attributes. Runs at the speed of 8 threads. Continue to pass at breakpoint. And create a time log.

Incremental backup

Back up modified files recently

Robocopy c:\ abc d:\ monday / mir / copyall / dcopy:DAT / w robocopy 1 / r robocopy 1 / maxage:1 / mt:8

The effect is to back up all modified files within one day in C\ abc to the Monday folder.

Add / z to support breakpoint continuation

/ xa:h can only exclude hidden files, and there is currently no command for hidden directories. Hidden directories can only be excluded with the / XD directory name.

Robocopy c:\ d:\ aaa / e / XD "System Volume Information" / XD $RECYCLE.BIN / Amuraza H

For robocopy operations on the root directory, you need to remove the System Volume Information and $RECYCLE.BIN directories and clear the hidden folder properties with the / XD parameter, / Amurazh.

@ echo off

Title Robocopy daily regular mirror backup script

Echo.

Echo anti-daze: please modify this script configuration and delete this line

Pause > nul

: set the current date name

Set yawns% daterids 0Magi 4% daterids 5pas 2% daterids 8 pas 2%

Backup frequency *

Set pinlv=daily

Enter backup time format "22:00" *

Set time=20:00

: save log, BAT, mail plug-ins *

Set weizhi=E:\ RCMB%y%

Source road strength *

Set yuan= "D:\ abc"

: target road strength *

Set mubiao= "E:\ abc"

: task name *

Set taskname=DailyMBCopy

: set up mail

Set from=abc@yeah.net

Set user=abc

Set pass=password

Set to=12345@qq.com,678910@qq.com

Set smtp=smtp.yeah.net

Mail script parameter

Set aversion% y%%

Set b=%%~dp0Log\ Robocopy\ RBLog%%y%%.txt

Set c=%%~dp0Log\ Blatmail\ Maillog%%y%%.txt

Set d=Robocopy mirror replication task has been completed

Set estrangement% from%

Set favored% user%

Set gaming% pass%

Set hints% to%

Set iTunes% SMTP%

If exist "weizhi%" goto abc

Md "weizhi%"

Md "% weizhi%\ Log"

Md "% weizhi%\ Log\ Robocopy"

Md "% weizhi%\ Log\ Blatmail"

If exist "mubiao%" goto abc

Md "mubiao%"

Create a replication script

Echo @ echo off >% weizhi%\ robocopy_sc.bat

Echo title executes RCMB task script ING > >% weizhi%\ robocopy_sc.bat

Between 0: 00 a.m. and 10:00, if you use the online batch naming method, there will be a space. Causes the name to not be applied.

Echo if "% time:~0,2%%" lss 10 (set 2%% date 5 2%% 2%% date 8 2% else 1% date 2%) else (date 2%% date 2% 5% 2%% date 2%% date 2%) >% weizhi%\ robocopy_sc.bat

: add / tee to check progress when executing commands / np closed file percentage / xa:sht excluded system, hidden, temporary file / mt:8 enabled 8 threads

Echo robocopy% yuan%% mubiao% / mir / copyall / dcopy:DAT / mt:8 / z / xa:sht / a Log / ts / log:%weizhi%\ Log\ RBLog%%y%%.txt ^ > nul > >% weizhi%\ robocopy_sc.bat

Echo start "% weizhi%\ blatmail\ blatmail.bat% a% b% c% d% e% f% g% h% I% ^ > nul >% weizhi%\ robocopy_sc.bat

Create a test script that views and executes tasks

Echo @ echo off >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo title views and executes this task > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo->% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo schtasks / query / tn% taskname% / v / fo list > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo->% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo. > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo. > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo. > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Any key of echo echo executes the task immediately > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo pause > nul > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo schtasks / run / tn% taskname% > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo echo any key exit > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo pause > nul > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Echo exit > >% weizhi%\ RunRobocopySchtaskImmediately.bat

Copy mail program

Robocopy "% ~ dp0blatmail"% weizhi%\ blatmail" / e > nul

: create task

Schtasks / create / sc% pinlv% / tn% taskname% / tr "% weizhi%\ robocopy_sc.bat" / st% time% / rl highest / f

Echo any key to view the task

Pause > nul

Cls

Echo.

Echo.

Echo.

Echo-

Schtasks / query / tn% taskname% / v / fo list

Echo-

Echo "press any key to continue"

Pause > nul

Goto abcd

: abcd

Start "" weizhi% "

Start "" mubiao% "

Exit

: abc

Cls

Echo.

Echo.

Echo.

Echo.

The echo directory already exists. Delete it manually and try again.

Echo any key to exit

Pause > nul

Exit

The other script is an incremental backup of Robocopy at a regular time every day.

See download for details.

Finally, send the mail using Blatmail. Download is visible.

This is the directory folder that is automatically created after running the script.

Script configuration daily timing synchronization scheduled tasks

The effect is as follows

This is the email effect:

Attached are Robocopy synchronization and incremental synchronization scripts, Blatmail files.

Http://down.51cto.com/data/2446578

If you need Robocopy software for XP, you can use the GUI version of Robocopy directly. Net 2.0 is required for installation.

Https://technet.microsoft.com/zh-tw/library/2006.11.utilityspotlight.aspx

If you want users to click and change the "access time", and then use the access time to make a copy of the robocoy, you can refer to the following article.

"Why are the access time and modification time inconsistent in the file properties?"

Https://blog.csdn.net/D_R_L_T/article/details/74611126

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report