windows - Fejl ved brug af IF ELSE

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg skriver dette script, og alt fungerede fejlfrit, indtil jeg tilføjer den hvis ellers del ... Så vender den tilbage Kommandotens syntaks er forkert


Hvis jeg fjerner det, poof, det virker. Hvis jeg forsøger at holde om ellers og ændre keglen inde til bare et ekko, poof, virker det også. Så jeg er ikke sikker på, hvad der kan være problemet, og hvordan man korrekt fejler det ...


@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\%ackup\_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 Files7-Zip7z.exe" a \%ZIPFILE\% "\%SrcFolder\%"

    "c:Program Files7-Zip7z.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
)


Tak på forhånd!


EDIT: Som foreslået af Margoo kunne jeg ordne det ved at fjerne al koden fra If-koden og kalde den med CALL :label.


Nu ser det sådan ud:


goto ifelse

:start
cd \%Folder\%

del \%ZIPFILE\%
del \%ZIPFILE\%.gpg

"c:Program Files7-Zip7z.exe" a \%ZIPFILE\% "\%SrcFolder\%"

"c:Program Files7-Zip7z.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
)

Bedste reference