简化批量备份脚本
Simplifying batch backup script
我已经制作了这个脚本(减去我所有的 ECHO 以方便您阅读)以将某些用户文件夹备份到外部设备。它运行完美,但我想知道是否有人对我如何简化它有任何想法(例如,更多 'clever')。
我是这个网站和编码的新手。请多多包涵!
感谢所有帮助。
@ECHO OFF
SET driveLetter=%~d0
:CHOOSE
SET /P CHOOSE=Are you sure you want to continue [Y/N]?
IF /I "%CHOOSE%" == "Y" GOTO :chooseYes
IF /I "%CHOOSE%" == "N" GOTO :chooseNo
GOTO :CHOOSE
:chooseYes
MKDIR %driveLetter%\Desktop
MKDIR %driveLetter%\Documents
MKDIR %driveLetter%\Favorites
MKDIR %driveLetter%\Pictures
MKDIR %driveLetter%\Downloads
TIMEOUT /T 1 /NOBREAK >NUL
ROBOCOPY %USERPROFILE%\Desktop\ %driveLetter%\Desktop /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Documents\ %driveLetter%\Documents /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Favorites\ %driveLetter%\Favorites /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Pictures\ %driveLetter%\Pictures /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Downloads\ %driveLetter%\Downloads /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
:chooseNo
TIMEOUT /T 3 /NOBREAK >NUL
此致。
如果可以,请不要重复自己
:chooseYes
for %%a in ( Desktop Documents Favorites Pictured Downloads ) do (
robocopy "%userprofile%\%%a" "%driveLetter%\%%a" /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
注意:mkdir
已被禁止,因为 robocopy
命令将创建目标文件夹
我已经制作了这个脚本(减去我所有的 ECHO 以方便您阅读)以将某些用户文件夹备份到外部设备。它运行完美,但我想知道是否有人对我如何简化它有任何想法(例如,更多 'clever')。
我是这个网站和编码的新手。请多多包涵!
感谢所有帮助。
@ECHO OFF
SET driveLetter=%~d0
:CHOOSE
SET /P CHOOSE=Are you sure you want to continue [Y/N]?
IF /I "%CHOOSE%" == "Y" GOTO :chooseYes
IF /I "%CHOOSE%" == "N" GOTO :chooseNo
GOTO :CHOOSE
:chooseYes
MKDIR %driveLetter%\Desktop
MKDIR %driveLetter%\Documents
MKDIR %driveLetter%\Favorites
MKDIR %driveLetter%\Pictures
MKDIR %driveLetter%\Downloads
TIMEOUT /T 1 /NOBREAK >NUL
ROBOCOPY %USERPROFILE%\Desktop\ %driveLetter%\Desktop /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Documents\ %driveLetter%\Documents /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Favorites\ %driveLetter%\Favorites /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Pictures\ %driveLetter%\Pictures /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Downloads\ %driveLetter%\Downloads /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
:chooseNo
TIMEOUT /T 3 /NOBREAK >NUL
此致。
如果可以,请不要重复自己
:chooseYes
for %%a in ( Desktop Documents Favorites Pictured Downloads ) do (
robocopy "%userprofile%\%%a" "%driveLetter%\%%a" /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
注意:mkdir
已被禁止,因为 robocopy
命令将创建目标文件夹