我创建了以下批处理文件,但没有成功。
@ECHO OFF
@ECHO "Backup process started."
@SET TARGET_FILES = "\\pc1\temp\*.mdb"
@ECHO "TARGET_FILES:%TARGET_FILES%"
@SET DESTINATION_FOLDER = "\\pc1\temp\Backups"
@ECHO "DESTINATION_FOLDER:%DESTINATION_FOLDER%"
@SET BACKUP_FOLDER = "Backup%date:~10,4%%date:~4,2%%date:~7,2%"
@ECHO "BACKUP_FOLDER:%BACKUP_FOLDER%"
@SET FINAL_FOLDER = "%DESTINATION_FOLDER%\%BACKUP_FOLDER%"
MKDIR %FINAL_FOLDER%
@ECHO "DIRECTORY CREATED:%FINAL_FOLDER%"
XCOPY %TARGET_FILES% %FINAL_FOLDER% >> %FINAL_FOLDER%\%BACKUP_FOLDER%.log
@ECHO "Backup process ended successfully."
@ECHO ON
环境:使用 Windows XP SP3 将在 C:\Windows\Tasks 中的计划任务
输出:
"Backup process started."
"TARGET_FILES:"
"DESTINATION_FOLDER:"
"BACKUP_FOLDER:"
The syntax of the command is incorrect.
"DIRECTORY CREATED:"
Invalid number of parameters
"Backup process ended successfully."
感谢任何有关正确方向的指导。
UPDATES1: 我注意到我的变量没有设置。
更新2:
@ECHO OFF
ECHO Backup process started.
set TARGET_FILES=\\pc1\temp\*.mdb
ECHO TARGET_FILES "%TARGET_FILES%"
SET DESTINATION_FOLDER=\\pc1\temp\Backups
ECHO DESTINATION_FOLDER "%DESTINATION_FOLDER%"
SET BACKUP_FOLDER=Backup%date:~0,4%%date:~5,2%%date:~8,2%
ECHO BACKUP_FOLDER "%BACKUP_FOLDER%"
SET FINAL_FOLDER=%DESTINATION_FOLDER%\%BACKUP_FOLDER%
MKDIR "%FINAL_FOLDER%"
ECHO DIRECTORY CREATED "%FINAL_FOLDER%"
XCOPY "%TARGET_FILES%" "%FINAL_FOLDER%" >> "%FINAL_FOLDER%\%BACKUP_FOLDER%.log"
ECHO Backup process ended successfully.
@ECHO ON
更新的输出2:
Backup process started.
TARGET_FILES "\\pc1\temp\*.mdb"
DESTINATION_FOLDER "\\pc1\temp\Backups"
BACKUP_FOLDER "Backup20120214"
DIRECTORY CREATED "\\pc1\temp\Backups\Backup20120214"
Backup process ended successfully.
日志
\\pc1\temp\file1.mdb
\\pc1\temp\file1_be.mdb
2 File(s) copied
使用新代码 (UPDATES2),我已成功将所有 mdb 文件复制到目标文件夹,但未记录所有回显消息。如何包含要记录的所有回显消息?