我正在尝试批量备份工作服务器上的文件夹。 (请参阅附件链接) Bat Error "invalid number of parameters"
长话短说 - 我需要脚本为每个备份命名一个新文件夹,建议使用“md new_folder”,但我似乎无法获取上下文或如何将其放入代码中。 <击> 撞击>
<击>@echo This will now create a new backup of S:\Internal Auditor\9 - September 14
@echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKINGUP SOME DATA########
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
@pause
非常感谢任何帮助!
----------的 编辑: 我尝试了一行代码,让我慢慢接近:----------
@echo This will now create a new backup of S:\Internal Auditor\9 - September 14
@echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy %SRCFOLDER% "%DESTFOLDER%\%folder%" %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
@pause
但是 - 我得到以下输出:
This will now create a new backup of S:\Internal Auditor\9 - September 14
Access is denied.
Error occurred while processing: S:\Internal.
A subdirectory or file Auditor\2014\9 already exists.
Error occurred while processing: Auditor\2014\9.
A subdirectory or file - already exists.
Error occurred while processing: -.
A subdirectory or file Sept already exists.
Error occurred while processing: Sept.
A subdirectory or file Backup\9/-9/-Tue already exists.
Error occurred while processing: Backup\9/-9/-Tue .
######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
Invalid number of parameters
!!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
Press any key to continue . . .
击> <击> 撞击>
---------- 编辑2:我尝试了一行代码,让我慢慢接近:----------
我已经按照我在网上找到的建议和一些事情,现在我到了一些错误的地步:
md "S:\Internal Auditor\~\09/12/2014"
A subdirectory or file S:\Internal Auditor\~\09/12/2014 already exists.
和
xcopy "S:\Internal Auditor\9 - September 14 S:\Internal Auditor\2014\9 - Sept Backup\09/12/2014
/W /E /H /V /C /Z /I /F /J /R /Y /D
File not found - 09/12/2014 /W /E /H /V /C /Z /I /F /J /R /Y /D
这是我的代码:
@echo This will now create a new backup of S:\Internal Auditor\9 - September 14
Rem Backup 9 - September 14
@echo
:: variables
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y /D
@echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy "%SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%"
@echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
@pause
此外,当我运行代码时,它会生成一个新目录〜\ 09 \ 12 \ 2014而不是所需的〜\ 09/12/2014。 澄清: 它创建了3个新的子目录,而不是一个新的子目录。
答案 0 :(得分:0)
好的,让我们看看你在做什么。您的变量folder
是根据短日期的本地设置设置的,对我来说,例如Tue 09/09/2014
所以%date:~0,4%
将是Tue
。使用echo命令确保您获得所需内容:
echo %date:~5,2%-%date:~8,2%-%date:~0,4%
但是现在让我们假设你已经知道了,%folder%
包含了你想要的东西。这是一条线上的两个命令,在最坏的情况下最多不会起作用,它会创建一堆你没想到的文件夹:
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
您想将其拆分为2行,并且您希望将新的基于日期的文件夹名称用作目标的一部分,我确定。所以这会做到这一点:
md "%DESTFOLDER%\%folder%"
然后复制您需要在目的地中加入\%folder%
:
xcopy %SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%
但我认为,而且我知道我不应该要求澄清,但也许如果我错了,你应该在你的问题中澄清你需要的东西,你真的想要S:\Internal Auditor\2014\9 - Sept Backup
是S:\Internal Auditor\
加上%folder%
中的值,而不是该路径中的日期。
建议:将%folder%
变量设置为yyyy-mm-dd
格式,例如2014-09-09,以便它可以排序,并在目的地中使用它。
答案 1 :(得分:0)
确定。有一些错误:
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
必须(安全方法,在SRCFOLDER
和DESTFOLDER
开头添加第一个引号):
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"