我正在尝试使用此脚本备份特定的文件夹/文件并压缩它们,然后将zip文件移动到diff文件夹。
但我一直收到错误。
@ECHO off
SETLOCAL
ECHO + Setting up environment variables.
SET BACKPATH=%ThisService_RootDirectory%temp\
SET ARCPATH=C:\Program Files\7-Zip\7z.exe
SET ARCPARAMS=a -y
SET DAYSTOKEEP=3
SET ARCHIVE_DAYSTOKEEP=30
SET SOURCEPATH=%ThisService_RootDirectory%MPMissions
SET DEST_PATH=%ThisService_RootDirectory%Backups
SET BACKUP_DEST=%date:~-7,2%-%date:~4,2%-%date:~-4,4%
IF NOT EXIST "%BACKPATH%" (
ECHO ! Backup Path not found, exiting.
GOTO END
) ELSE (
ECHO * Backup Path Found.
)
IF NOT EXIST "%ARCPATH%" (
ECHO ! Archiver not found, exiting.
GOTO END
) ELSE (
ECHO * Archiver Found.
)
ECHO * Copying Files...
xcopy "%SOURCEPATH%\Documents" "%BACKPATH%\%BACKUP_DEST%\MPMissions" /v /e /s /i /y 1>NUL 2>NUL
ECHO * Archiving files...
CD /D "%BACKPATH%"
FOR /f %%a IN ('FORFILES /P %BACKPATH% /C "cmd /c if @isdir==TRUE echo @file" /D -%DAYSTOKEEP%') DO (
IF NOT EXIST %%a.7z (
"%ARCPATH%" %ARCPARAMS% %%a.7z %BACKPATH%\%%a\*.* 1>NUL 2>NUL
copy %%a.7z %DEST_PATH% 1>NUL 2>NUL
del %%a.7z 1>NUL 2>NUL
)
)
ECHO * Cleaning folders older than %DAYSTOKEEP% days..
FORFILES /P %BACKPATH% /C "cmd /c if @isdir==TRUE rmdir /s /q @file" /D -%DAYSTOKEEP% 1>NUL 2>NUL
ECHO * Cleaning files older than %DAYSTOKEEP% days..
FORFILES /P %BACKPATH% /M *.7z /C "cmd /c if @isdir==FALSE del @file" /D -%DAYSTOKEEP% 1>NUL 2>NUL
ECHO * Cleaning archives files older than %ARCHIVE_DAYSTOKEEP% days..
FORFILES /P %DEST_PATH% /M *.7z /C "cmd /c if @isdir==FALSE del @file" /D -%ARCHIVE_DAYSTOKEEP% 1>NUL 2>NUL
:END
ENDLOCAL
一旦我运行脚本,就会显示以下消息:
现在变量%ThisService_RootDirectory%是tcadmin的一部分,这是一个游戏服务器服务,因此我执行批处理脚本的变量会将该变量转换为用户服务的实际路径 例: %ThisService_RootDirectory% 是 C:\ TCAFiles \用户\管理员\ 5 \
该脚本将文件复制到所需的文件夹,但它似乎没有压缩文件并将zip文件移动到所需的文件夹。
请有人在这里给予一些帮助。
原始来源位于https://community.spiceworks.com/topic/482860-batch-script-to-transfer-and-compress