0

I have a .cmd file that i want to use in automating copying a folder from a mapped location on a windows 2008 server to an external HDD connected to the windows server box:

@ECHO OFF
ECHO Backup process started.
set TARGET_FOLDER=Z:\"WindowsImageBackup - Copy"
ECHO TARGET_FOLDER "%TARGET_FOLDER%"
SET DESTINATION_FOLDER=H:\SERVER_BACKUP_IMAGE
ECHO DESTINATION_FOLDER "%DESTINATION_FOLDER%"
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set mydate=%%d%%c%%b%%a)
For /f "tokens=1-2 delims=: " %%a in ('time /t') do (set mytime=%%a%%b)
SET BACKUP_FOLDER=BACKUP_%mydate%_%mytime%
ECHO BACKUP_FOLDER "%BACKUP_FOLDER%"
SET FINAL_FOLDER=%DESTINATION_FOLDER%\%BACKUP_FOLDER%
MKDIR "%FINAL_FOLDER%"
ECHO DIRECTORY CREATED "%FINAL_FOLDER%"
ECHO Backup process started ...
XCOPY "%TARGET_FOLDER%" "%FINAL_FOLDER%" >> "%FINAL_FOLDER%\%BACKUP_FOLDER%.log" /Y
ECHO Backup process ended successfully.
@ECHO ON
pause

After running the script, the destination folder is created and the log file created says 0 files copied but there are files in the target folder. This is the output:

Backup process started. TARGET_FOLDER "Z:\"WindowsImageBackup - Copy"" DESTINATION_FOLDER "H:\SERVER_BACKUP_IMAGE" BACKUP_FOLDER "BACKUP_20131409Sat_0333" DIRECTORY CREATED "H:\SERVER_BACKUP_IMAGE\BACKUP_20131409Sat_0333" Backup process started ... Invalid number of parameters Backup process ended successfully.

C:\Control>pause Press any key to continue . . .

The 7th line is of interest but I do not know how to go around it. What parameters am i supposed to use?

Funny thing is that if i run this same script on my windows 7 laptop (i have the same directory structure), it runs and copies accordingly.

Thanks for your help.

4

2 回答 2

0

/Y 位于错误的位置,xcopy 没有文件规范,并且您的文件路径引用需要像 Endoro 提到的那样进行一些清理。这就是我将如何使用您的代码风格(和 wmic 来获得强大的日期/时间戳)。

@ECHO OFF
ECHO Backup process started.
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%

set "TARGET_FOLDER=Z:\WindowsImageBackup - Copy"
SET "DESTINATION_FOLDER=H:\SERVER_BACKUP_IMAGE"
SET "BACKUP_FOLDER=BACKUP_%fullstamp%"
SET "FINAL_FOLDER=%DESTINATION_FOLDER%\%BACKUP_FOLDER%"

ECHO TARGET_FOLDER "%TARGET_FOLDER%"
ECHO DESTINATION_FOLDER "%DESTINATION_FOLDER%"
ECHO BACKUP_FOLDER "%BACKUP_FOLDER%"
MKDIR "%FINAL_FOLDER%" 2>nul
ECHO DIRECTORY CREATED "%FINAL_FOLDER%"
ECHO Backup process started ...
XCOPY "%TARGET_FOLDER%\*.*" "%FINAL_FOLDER%\" /Y >>"%FINAL_FOLDER%\%BACKUP_FOLDER%.log" 
ECHO Backup process ended
pause
于 2013-09-15T01:24:00.537 回答
0

您的报价需要改进:

set "TARGET_FOLDER=Z:\WindowsImageBackup - Copy"
于 2013-09-14T16:37:11.203 回答