2017-06-22 23 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

相关问题