如何为将大文件复制到共享文件夹的批处理文件安排任务?

时间:2012-02-14 05:14:01

标签: batch-file scheduled-tasks

主批处理文件(main.bat):

@ECHO OFF
ECHO Backup process started.

set TARGET_FILES=\\pc1\folder1\*.mdb
ECHO TARGET_FILES "%TARGET_FILES%"

SET DESTINATION_FOLDER=\\pc2\folder1\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%
ECHO DIRECTORY CREATED "%FINAL_FOLDER%"

XCOPY "%TARGET_FILES%" "%FINAL_FOLDER%"

ECHO Backup process ended successfully.

@ECHO ON

要执行的批处理文件并记录main.bat(execute.bat):

@ECHO OFF
SET DESTINATION_FOLDER=\\pc2\folder1\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%"

SET LOG_FILE=%FINAL_FOLDER%\%BACKUP_FOLDER%.log
ECHO LOG_FILE "%LOG_FILE%"

main.bat >> "%LOG_FILE%"
@ECHO ON

我已正确设置了预定任务。 我通过手动执行它来测试它(右键单击 - >运行)。 它执行任务但不复制mdb文件并且不创建备份文件夹。 我尝试将TARGET_FILES从*.mdb更改为*.txt,它会按预期执行。

mdb和txt文件的唯一区别是大小。 mdb文件各有500MB,而txt文件各有2KB。

对正确方向的任何指导表示赞赏。

1 个答案:

答案 0 :(得分:0)

我通过将两个共享文件夹映射到特定驱动器然后在批处理文件中使用它而不是完整路径来解决了这个问题。