@echo off
set path=%SystemRoot%\system32;%SystemRoot%;%ProgramFiles%\7-zip
set host=218.88.206.110
set tempdir=C:\CIMation\tmp_trans
move C:\CIMation\CMQMR\*.xml %tempdir%
if exist %tempdir%\XML-archive.tar.xz (
7z e %tempdir%\XML-archive.tar.xz -o%tempdir%
del /q %tempdir%\XML-archive.tar.xz
)
7z a -sdel -ttar %tempdir%\XML-archive.tar %tempdir%\*.xml
7z a -sdel -txz %tempdir%\XML-archive.tar.xz %tempdir%\XML-archive.tar
ping -n 1 "%host%" | findstr /r /c:"[0-9]*ms"
if %errorlevel% == 0 (
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script="C:\Program Files (x86)\WinSCP\5-xml-use-7z-archive-and-update.sh"
) else (
echo VFPA server: %host% network PING Failure.
echo ..
rem echo ...Waiting for 1 min, end this process.
rem ping 127.0.0.1 -n 60 >nul
)
经过一段时间使用,发现一些逻辑上的问题: 在上传服务器不可达的情况下, 上传失败的文件在本地会积累很多。虽然最终会被压缩,但在周期性计划执行期间,每次被解压后,将会占用磁盘空间;逻辑上在7zip运行过程中,甚至会产生2份未压缩的打包文件; 极端情况下(新增文件足够多、或上传服务器中断时间过长), 将会耗尽磁盘所有空间。
在这种情况下, 需要另加判断逻辑:如果未上传的打包文件超过5M,就将其加注时间戳改名,再另产生新文件; 改名后的打包文件,另行处理。
修改版本如下:
@echo off
set today=%date:~10,4%-%date:~4,2%-%date:~7,2%
set ctime=%TIME: =0%
set tname=%today%-%ctime:~0,2%%ctime:~3,2%%ctime:~6,2%
set path=%SystemRoot%\system32;%SystemRoot%;%ProgramFiles%\7-zip
set HP-host=218.88.206.110
set tempdir=C:\CIMation\tmp_trans
if exist C:\CIMation\CMQMR\*.xml (
move C:\CIMation\CMQMR\*.xml %tempdir%
if exist %tempdir%\XML-archive.tar.xz (
for /f "delims=" %%i in ("%tempdir%\XML-archive.tar.xz") do (
if %%~zi GTR 5120000 (
ren %tempdir%\XML-archive.tar.xz XML-archive-%tname%.tar.xz
) else (
7z e %tempdir%\XML-archive.tar.xz -o%tempdir%
del /q %tempdir%\XML-archive.tar.xz
)
)
)
7z a -sdel -ttar %tempdir%\XML-archive.tar %tempdir%\*.xml
7z a -sdel -txz %tempdir%\XML-archive.tar.xz %tempdir%\XML-archive.tar
)
ping -n 2 "%HP-host%" | findstr /r /c:"[0-9]*ms"
if exist %tempdir%\XML-archive.tar.xz (
if %errorlevel% == 0 (
cd "C:\Program Files (x86)\WinSCP"
WinSCP.exe /console /script=5-xml-use-7z-archive-and-upload.sh
) else (
echo VFPA server: Network PING Failure.
echo ..
)
)
不得不说,LZMA2压缩率真变态,对文本文件居然达到了将近100:1 。 我一个压缩后不到100M的文件,解压后居然有10GB ...