打包本地文件, 並使用Winscp上傳腳本

@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,就將其加註時間戳更名,再另產生新文件; 更名後的打包文件,另行處理。this

修改版本以下:code

@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 ...server

相關文章
相關標籤/搜索