2017-06-22 199 views
0

我有以下腳本我有拼湊起來,以幫助的備份Autodesk Vault中專業:批處理文件::如果LSS工作不正常

@echo off 
setlocal enableDelayedExpansion 
echo setting up variables... 
SET VAULTBACKUPPATH=C:\Users\alex.fielder\Dropbox\Graitec\Vault Backup 
SET LOGFILEPATH=C:\Users\alex.fielder\Dropbox\Graitec\GRA0387AF_Vault_Backup.txt 
SET SEVENZIPLOGFILEPATH=C:\Users\alex.fielder\Dropbox\Graitec\GRA0387AF_Zip_Log.txt 
SET SEVENZIPPATH=C:\ProgramData\chocolatey\bin\7za.exe 
SET ADMSCONSOLEPATH=C:\Program Files\Autodesk\ADMS Professional 2017\ADMS Console\Connectivity.ADMSConsole.exe 
SET NUMDAYSBACKUPTOKEEP=-15 
SET MINMEMVALUE=2000000 
SET MINDRIVESPACE=10000000 
echo testing available system resources 
for /f "skip=1" %%p in ('wmic os get freephysicalmemory') do (SET AVAILABLESYSTEMMEMORY=%%p) 
rem echo "%AVAILABLESYSTEMMEMORY%" 
if !AVAILABLESYSTEMMEMORY! LSS %MINMEMVALUE% (
    echo "%DATE% %TIME%: low available system memory, exiting" >> %LOGFILEPATH% 
    exit /b 1 
) ELSE (
    echo "%DATE% %TIME%: sufficient system memory, continuing" >> %LOGFILEPATH% 
) 
echo checking free disk space on C:\ 
FOR /F "usebackq tokens=3" %%s IN (`DIR C:\ /-C /-O /W`) DO (
    SET FREE_SPACE=%%s 
) 
if !FREE_SPACE! LSS !MINDRIVESPACE! (
    echo "%DATE% %TIME%: low space on C:, exiting" >> %LOGFILEPATH% 
    exit /b 1 
) ELSE (
    echo "%DATE% %TIME%: sufficient space on C:\, continuing" >> %LOGFILEPATH% 
) 
REM echo stopping and disabling Sophos 
REM wmic service where "caption like 'Sophos%%'" call Stopservice 
REM wmic service where "caption like 'Sophos%%' and Startmode<>'Disabled'" call ChangeStartmode Disabled 
echo pausing Dropbox, Searchindexer, Everything using the sysinternals tool PSSuspend! 
pssuspend dropbox 
pssuspend searchindexer 
pssuspend everything 


echo changing to working folder 
cd "C:\Users\alex.fielder\Dropbox\Graitec\Vault Backup" 
echo removing existing backup directories if there are any present 
for /f %%i in ('dir /a:d /b Vault*') do rd /s /q %%i 
echo performing vault backup from Vault Professional 2017 
REM -WA is short for Windows Authentication - does not work with Vault basic! 
call "%ADMSCONSOLEPATH%" -Obackup -B"%VAULTBACKUPPATH%" -WA -VAL -DBSC -S -L"%LOGFILEPATH%" 

echo Beginning zip and verification using 7zip %date% - %time% >> "%SEVENZIPLOGFILEPATH%" 
for /f "Tokens=*" %%i in ('dir /a:d /b Vault*') do (
echo creating a .7z archive of latest backup using the 7zip command line. 
call "%SEVENZIPPATH%" a -t7z "%%i.7z" "%%i" -mmt -mx1 
echo testing the archive - results can be found in the Vault backup log file! 
call "%SEVENZIPPATH%" t "%%i.7z" -mmt -r >> "%SEVENZIPLOGFILEPATH%" 
) 
echo completed zip and verification using 7zip %date% - %time% >> "%SEVENZIPLOGFILEPATH%" 

REM for /f "Tokens=*" %%i in ('dir /b Vault*.7z') do call "%SEVENZIPPATH%" t "%%i" -mmt -r >> "%SEVENZIPLOGFILEPATH%" 

echo removing backup directory to prevent Dropbox syncing it to the cloud. 
for /f %%i in ('dir /a:d /b Vault*') do rd /s /q %%i 
echo removing backups older than 30 days to prevent Dropbox space getting eaten up unecessarily. 
forfiles /p "%VAULTBACKUPPATH%" /s /m *.* /d "%NUMDAYSBACKUPTOKEEP%" /c "cmd /c del @path" 
echo resuming Dropbox, Searchindexer, Everything and Sophos 
pssuspend -r dropbox 
pssuspend -r searchindexer 
pssuspend -r everything 
REM wmic service where "caption like 'Sophos%%' and Startmode='Disabled'" call ChangeStartmode Automatic 
REM wmic service where "caption like 'Sophos%%'" call Startservice 
echo finished! 

所有這一切工作正常,除了我加了本節檢查系統資源/空間上C:驅動器,我不能得到正確的語法爲它:

echo testing available system resources 
for /f "skip=1" %%p in ('wmic os get freephysicalmemory') do (SET AVAILABLESYSTEMMEMORY=%%p) 
rem echo "%AVAILABLESYSTEMMEMORY%" 
if !AVAILABLESYSTEMMEMORY! LSS %MINMEMVALUE% (
    echo "%DATE% %TIME%: low available system memory, exiting" >> %LOGFILEPATH% 
    exit /b 1 
) ELSE (
    echo "%DATE% %TIME%: sufficient system memory, continuing" >> %LOGFILEPATH% 
) 
echo checking free disk space on C:\ 
FOR /F "usebackq tokens=3" %%s IN (`DIR C:\ /-C /-O /W`) DO (
    SET FREE_SPACE=%%s 
) 
if !FREE_SPACE! LSS !MINDRIVESPACE! (
    echo "%DATE% %TIME%: low space on C:, exiting" >> %LOGFILEPATH% 
    exit /b 1 
) ELSE (
    echo "%DATE% %TIME%: sufficient space on C:\, continuing" >> %LOGFILEPATH% 
) 

誰能提供任何指針,我怎麼可能糾正呢?

我沒有找到這個帖子:

Batch file :: if lss is not working properly

但你可以在上面看到,我已經嘗試了幾種不同的變化,沒有成功的工作。

謝謝,

Alex。

+0

您正在比較有符號的32位整數的數字還是它們可能太大? – aschipfl

+0

如果是這樣,填充每個20前導零,並比較兩個結果字符串的最後20個字符,引用每個字符串,以確保您強制進行字母比較。 – Magoo

+0

@aschipfl:我不確定你的意思?該數字存儲在腳本頂部附近的變量,即:SET MINMEMVALUE = 2000000 SET MINDRIVESPACE = 10000000 – AlexFielder

回答

1

您可以嘗試不同的方法,讓WMI確定是否低於最小值。

@ECHO OFF 

ECHO Setting up variables... 

SET "LOGFILEPATH=C:\Users\alex.fielder\Dropbox\Graitec\GRA0387AF_Vault_Backup.txt" 
SET "MINMEMVALUE=2000000" 
SET "MINDRIVESPACE=10000000" 

ECHO Testing available system resources 

ECHO Checking free system memory 
SET "FPM=sufficient system memory, continuing" 
FOR /F "USEBACKQ EOL=F" %%A IN (`WMIC OS WHERE^ 
"FreePhysicalMemory < '%MINMEMVALUE%'" GET FreePhysicalMemory 2^>NUL` 
) DO FOR %%B IN (%%A) DO SET "FPM=%%B" 
IF NOT "%FPM%"=="sufficient system memory, continuing" (
    SET "FPM=low available system memory, exiting") 
ECHO "%DATE% %TIME%: %FPM%">>"%LOGFILEPATH%" 

ECHO Checking free system drive space 
SET "SFP=sufficient space on %SystemDrive%, continuing" 
FOR /F "USEBACKQ EOL=F" %%A IN (`WMIC LOGICALDISK WHERE^ 
    "DeviceID = '%SystemDrive%' AND FreeSpace < '%MINDRIVESPACE%'"^ 
    GET FreeSpace 2^>NUL`) DO FOR %%B IN (%%A) DO SET "SFP=%%B" 
IF NOT "%SFP%"=="sufficient space on %SystemDrive%, continuing" (
    SET "SFP=low space on %SystemDrive%, exiting") 
ECHO "%DATE% %TIME%: %SFP%">>"%LOGFILEPATH%" 

PAUSE 
+0

Compo非常棒,非常感謝! – AlexFielder