我正在尝试找到一种简单的方法,只将已更改的文件部署到Web服务器以进行部署。在过去我曾经使用过MSBuild,可以告诉他只复制比目标文件更新的文件,但是我很着急并且不想试图找出更新版本的MSBuild。
我可以使用ROBOCOPY吗?有一个排除选项列表,其中包括:
排除究竟是什么意思?排除复制或排除覆盖?例如,如果我写了:
ROBOCOPY C:\ SourceFolder \ ABC.dll D:\ DestinationFolder / XO
这会只复制较新的文件,而不是相同年龄的文件吗?
或者有更好的工具可以做到这一点吗?
答案 0 :(得分:34)
回答你的所有问题:
我可以使用ROBOCOPY吗?
是的,RC应符合您的要求(简单,只需复制所需的内容)
排除是什么意思?
它将排除复制 - RC称之为正在跳过
/XO
选项是否只会复制较新的文件,而不会复制相同年龄的文件?
是的,RC只会复制较新的文件。将跳过相同年龄的文件。
(正确的命令是robocopy C:\SourceFolder D:\DestinationFolder ABC.dll /XO
)
使用/MIR
选项可能对您有用。通常,RC比单个文件更适合目录和目录树。
答案 1 :(得分:0)
您可以使用robocopy复制带有存档标志的文件并重置该属性。使用/ M命令行,这是我的备份脚本,只有很少的额外技巧。
此脚本需要NirCmd工具来保持鼠标移动,以便我的机器不会进入睡眠状态。脚本使用锁定文件来判断备份脚本何时完成并且mousemove.bat脚本已关闭。你可以放弃这部分。
另一个是7-Zip工具,用于拆分小于4GB文件的虚拟机文件,我的目标文件夹仍然是FAT32,因此这是必需的。我应该使用NTFS磁盘但尚未转换备份磁盘。
<强>备份robocopy.bat 强>
@REM https://technet.microsoft.com/en-us/library/cc733145.aspx
@REM http://www.skonet.com/articles_archive/robocopy_job_template.aspx
set basedir=%~dp0
del /Q %basedir%backup-robocopy-log.txt
set dt=%date%_%time:~0,8%
echo "%dt% robocopy started" > %basedir%backup-robocopy-lock.txt
start "Keep system awake" /MIN /LOW cmd.exe /C %basedir%backup-robocopy-movemouse.bat
set dest=E:\backup
call :BACKUP "Program Files\MariaDB 5.5\data"
call :BACKUP "projects"
call :BACKUP "Users\Myname"
:SPLIT
@REM Split +4GB file to multiple files to support FAT32 destination disk,
@REM splitted files must be stored outside of the robocopy destination folder.
set srcfile=C:\Users\Myname\VirtualBox VMs\Ubuntu\Ubuntu.vdi
set dstfile=%dest%\Users\Myname\VirtualBox VMs\Ubuntu\Ubuntu.vdi
set dstfile2=%dest%\non-robocopy\Users\Myname\VirtualBox VMs\Ubuntu\Ubuntu.vdi
IF NOT EXIST "%dstfile%" (
IF NOT EXIST "%dstfile2%.7z.001" attrib +A "%srcfile%"
dir /b /aa "%srcfile%" && (
del /Q "%dstfile2%.7z.*"
c:\apps\commands\7za.exe -mx0 -v4000m u "%dstfile2%.7z" "%srcfile%"
attrib -A "%srcfile%"
@set dt=%date%_%time:~0,8%
@echo %dt% Splitted %srcfile% >> %basedir%backup-robocopy-log.txt
)
)
del /Q %basedir%backup-robocopy-lock.txt
GOTO :END
:BACKUP
TITLE Backup %~1
robocopy.exe "c:\%~1" "%dest%\%~1" /JOB:%basedir%backup-robocopy-job.rcj
GOTO :EOF
:END
@set dt=%date%_%time:~0,8%
@echo %dt% robocopy completed >> %basedir%backup-robocopy-log.txt
@echo %dt% robocopy completed
@pause
<强>备份ROBOCOPY-job.rcj 强>
:: Robocopy Job Parameters
:: robocopy.exe "c:\projects" "E:\backup\projects" /JOB:backup-robocopy-job.rcj
:: Source Directory (this is given in command line)
::/SD:c:\examplefolder
:: Destination Directory (this is given in command line)
::/DD:E:\backup\examplefolder
:: Include files matching these names
/IF
*.*
/M :: copy only files with the Archive attribute and reset it.
/XJD :: eXclude Junction points for Directories.
:: Exclude Directories
/XD
C:\projects\bak
C:\projects\old
C:\project\tomcat\logs
C:\project\tomcat\work
C:\Users\Myname\.eclipse
C:\Users\Myname\.m2
C:\Users\Myname\.thumbnails
C:\Users\Myname\AppData
C:\Users\Myname\Favorites
C:\Users\Myname\Links
C:\Users\Myname\Saved Games
C:\Users\Myname\Searches
:: Exclude files matching these names
/XF
C:\Users\Myname\ntuser.dat
*.~bpl
:: Exclude files with any of the given Attributes set
:: S=System, H=Hidden
/XA:SH
:: Copy options
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/COPY:DAT :: what to COPY for files (default is /COPY:DAT).
/DCOPY:T :: COPY Directory Timestamps.
/PURGE :: delete dest files/dirs that no longer exist in source.
:: Retry Options
/R:0 :: number of Retries on failed copies: default 1 million.
/W:1 :: Wait time between retries: default is 30 seconds.
:: Logging Options (LOG+ append)
/NDL :: No Directory List - don't log directory names.
/NP :: No Progress - don't display percentage copied.
/TEE :: output to console window, as well as the log file.
/LOG+:c:\apps\commands\backup-robocopy-log.txt :: append to logfile
<强>备份ROBOCOPY-movemouse.bat 强>
@echo off
@REM Move mouse to prevent maching from sleeping
@rem while running a backup script
echo Keep system awake while robocopy is running,
echo this script moves a mouse once in a while.
set basedir=%~dp0
set IDX=0
:LOOP
IF NOT EXIST "%basedir%backup-robocopy-lock.txt" GOTO :EOF
SET /A IDX=%IDX% + 1
IF "%IDX%"=="240" (
SET IDX=0
echo Move mouse to keep system awake
c:\apps\commands\nircmdc.exe sendmouse move 5 5
c:\apps\commands\nircmdc.exe sendmouse move -5 -5
)
c:\apps\commands\nircmdc.exe wait 1000
GOTO :LOOP
答案 2 :(得分:-2)
看起来/e
选项就是您所需要的,它会跳过相同的文件/目录。
robocopy c:\data c:\backup /e
如果你运行两次命令,你会发现第二轮比较快,因为它会跳过很多东西。