我有以下脚本拼凑在一起以帮助备份Autodesk Vault Professional:
@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:Drive上的系统资源/空间,我无法获得正确的语法:
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
但正如您在上面所看到的,我尝试了几种不同的变体,但都没有成功。
谢谢,
亚历。
答案 0 :(得分: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