使用IF ELSE时出错

我正在写这个脚本,一切都完美无缺地工作,直到我添加if else部分…然后它返回的命令的语法是不正确的

如果我删除它,噗,它的作品。 如果我试着保持,如果更改锥体里面只是一个回声,噗,也行得通。 所以我不知道可能是什么问题,以及如何正确debugging它…

@echo off :: The only thing that normally needs to be changed is the Type variable. It should match the folder name where the .bak files are stored. set Type=DAILY set Datum=%date:~0,4%%date:~5,2%%date:~8,2% set Folder=C:\SQLBKP\ set Flag=%Folder%\%Type%\backup_ready.flg set ZIPFILE=%Folder%\%Type%-backup-%Datum%.zip set SrcFolder=%Folder%\%Type% set Passphrase=passwd set BUCKET=bucket @echo on IF exist %Flag% ( :start cd %Folder% del %ZIPFILE% del %ZIPFILE%.gpg "c:\Program Files\7-Zip\7z.exe" a %ZIPFILE% "%SrcFolder%" "c:\Program Files\7-Zip\7z.exe" t %ZIPFILE% | FIND "Everything is Ok" && goto continue || blat -to backupalerts@foo.com -server mail.protection.outlook.com -f backupalerts@foo.com -subject "%Type% backup integrity check failed on %computername%" -body "This script detected that the %Type% integrity check of the zipped folder failed on the machine %computername%." exit :continue @gpg --batch --passphrase %Passphrase% -c %ZIPFILE% aws s3 cp %ZIPFILE%.gpg s3://%BUCKET%/prefix/ || blat -to backupalerts@foo.com -server mail.protection.outlook.com -f backupalerts@foo.com -subject "%Type% backup failed on %computername%" -body "This script detected that the %Type% upload of the zipped folder to the S3 bucket failed on the machine %computername%." & exit del %Folder%\%Type%\*.bak del %ZIPFILE% del %ZIPFILE%.gpg exit ) ELSE ( timeout /t 600 goto start ) 

先谢谢你!

编辑:如Margoobuild议,我能够通过从if代码块中删除所有代码并使用CALL :label调用它来修复它。

现在看起来像这样:

 goto ifelse :start cd %Folder% del %ZIPFILE% del %ZIPFILE%.gpg "c:\Program Files\7-Zip\7z.exe" a %ZIPFILE% "%SrcFolder%" "c:\Program Files\7-Zip\7z.exe" t %ZIPFILE% | FIND "Everything is Ok" && goto continue || blat -to backupalerts@foo.com -server mail.protection.outlook.com -f backupalerts@foo.com -subject "%Type% backup integrity check failed on %computername%" -body "This script detected that the %Type% integrity check of the zipped folder failed on the machine %computername%." exit :continue @gpg --batch --passphrase %Passphrase% -c %ZIPFILE% aws s3 cp %ZIPFILE%.gpg s3://%BUCKET%/prefix/ || blat -to backupalerts@foo.com -server mail.protection.outlook.com -f backupalerts@foo.com -subject "%Type% backup failed on %computername%" -body "This script detected that the %Type% upload of the zipped folder to the S3 bucket failed on the machine %computername%." & exit del %Folder%\%Type%\*.bak del %ZIPFILE% del %ZIPFILE%.gpg exit :ifelse IF exist %Flag% ( call :begin ) ELSE ( timeout /t 600 call :begin )