打包本地文件, 并使用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,就将其加注时间戳改名,再另产生新文件; 改名后的打包文件,另行处理。

修改版本如下:

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

转载于:https://my.oschina.net/u/3362827/blog/890147

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值