Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 每个备份命令的新文件夹_Variables_Batch File_Cmd_Backup_Xcopy - Fatal编程技术网

Variables 每个备份命令的新文件夹

Variables 每个备份命令的新文件夹,variables,batch-file,cmd,backup,xcopy,Variables,Batch File,Cmd,Backup,Xcopy,我正在尝试获取一个用于备份工作服务器上文件夹的批处理。(请参阅附件链接) 长话短说-我需要脚本为每个备份命名一个新文件夹,建议使用“md new_folder”,但我似乎无法获得上下文或如何将其放入代码中。 任何帮助都将不胜感激 ----------编辑: 我尝试了一行代码,慢慢地让我更接近:---------- 但是-我得到以下输出: This will now create a new backup of S:\Internal Auditor\9 - September 14 Acce

我正在尝试获取一个用于备份工作服务器上文件夹的批处理。(请参阅附件链接)

长话短说-我需要脚本为每个备份命名一个新文件夹,建议使用“md new_folder”,但我似乎无法获得上下文或如何将其放入代码中。

任何帮助都将不胜感激

----------编辑: 我尝试了一行代码,慢慢地让我更接近:----------

但是-我得到以下输出:

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.
以及:

这是我的代码:

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 . . .
另外,当我运行代码时,它会生成一个新目录~\09\12\2014,而不是所需的~\09/12/2014。 澄清:
它创建了3个新的子目录,而不是一个新的子目录。

好的,让我们看看你在做什么。您的变量
文件夹
正在根据您的本地设置设置一个较短的日期,对我来说,例如
2014年9月9日星期二
,因此您的
%日期:~0,4%
将是
星期二
。使用echo命令确保您得到了想要的:

echo %date:~5,2%-%date:~8,2%-%date:~0,4%
但是现在我们假设您已经计算出,并且
%folder%
包含您想要的内容。这是一行中的两个命令,充其量也不起作用,但最坏的情况是,它将创建一堆您意想不到的文件夹:

"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
您希望将其拆分为两行,并且您希望使用新的基于日期的文件夹名称作为目标的一部分,我确信。因此,这将实现:

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,以便可排序,并在目的地使用该格式。

确定。有一些错误:

set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
必须是(安全方法,在
SRCFOLDER
DESTFOLDER
的开头添加第一个引号):


感谢您清除我桌面上的echo%date(我确实找到了一个我意想不到的文件夹)。XD并澄清:“S:\~\9-9月14日”是我需要备份的原始文件夹,以便将上面的内容复制到:“S:\~\9-9月备份”,但当它这样做时,我需要它在备份文件夹中创建一个新文件夹,日期和时间作为文件夹名称。另外:我可以做什么:set folder=%date:yyyy-mm ddNo,你必须像以前那样解析出日期的各个部分,但要注意这些部分是什么。毫无疑问,这个网站上有几十个例子。对于我的
Wed 09/10/2014
result fort today(美国标准格式),它将是
set folder=%date:~10,4%-%date:~4,2%-%date:~7,2%
,以获得
2014-10-09
。不要关闭
echo
,这样您将能够看到批处理文件的解析方式。你会发现你的报价有问题(例如,您定义了包含引号的DESTDIR,然后在
md
行中用另一对引号括起来,xcopy感谢您提出关闭“echo”的建议,这对我帮助很大……您将所有xcopy参数都括在引号中,而不是单独括在两个路径中。此外,您不能在路径名中包含/这一点“”是非法的。默认情况下,“set folder=%date:~4%会放置“/”。如果它是非法的,为什么会这样做?因为dos不是灵媒。它不知道您将使用该字符串作为文件夹名称。
md "%DESTFOLDER%\%folder%"
xcopy %SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"