批处理备份交换机日志的方法

作者: 不详 2013/6/17 23:10:34

华为交换机开启日志文件传送功能,发送到某服务器,现在需将收集的日志文件定期打包备份到金山快盘,写了一个批处理,跑在计划任务里。

日志文件如下图所示

每天都会生成,现在每月打包压缩一次,用RAR命令行,然后复制到金山快盘,效果如下图

批处理文件内容如下:

@echo off

cd /d E:\LogFiles

set CurMonth=%date:~5,2%

set LastMonth=00

set Year=%date:~0,4%

set /a LastYear=%Year%-1

echo 当前年份:%Year%

echo 当前月份:%CurMonth%

REM =====设定需备份的月份=====

if %CurMonth%==01 set LastMonth=12

if %CurMonth%==02 set LastMonth=01

if %CurMonth%==03 set LastMonth=02

if %CurMonth%==04 set LastMonth=03

if %CurMonth%==05 set LastMonth=04

if %CurMonth%==06 set LastMonth=05

if %CurMonth%==07 set LastMonth=06

if %CurMonth%==08 set LastMonth=07

if %CurMonth%==09 set LastMonth=08

if %CurMonth%==10 set LastMonth=09

if %CurMonth%==11 set LastMonth=10

if %CurMonth%==12 set LastMonth=11

echo 上月份:%LastMonth%

echo 去年年份:%LastYear%

REM =====用RAR的命令行进行打包压缩=====

REM dir Syslog%Year%-%LastMonth%*.txt

REM echo Syslog_%Year%-%LastMonth%.rar

REM dir Syslog%LastYear%-%LastMonth%*.txt

REM echo Syslog_%LastYear%-%LastMonth%.rar

if %LastMonth%==12 (

REM =====去年12月=====

echo =====去年12月=====

"c:\Program Files\WinRAR\Rar.exe" a -df Syslog_%LastYear%-%LastMonth%.rar Syslog%LastYear%-%LastMonth%*.txt

) else (

REM =====其它月份=====

echo =====其它月份=====

"c:\Program Files\WinRAR\Rar.exe" a -df Syslog_%Year%-%LastMonth%.rar Syslog%Year%-%LastMonth%*.txt

)

REM =====复制到金山快盘后删除源RAR文件=====

copy *.rar E:\SQLBak\SyslogBAK

del *.rar

然后在计划任务里设置每月1日运行此批处理即可。

特别推荐

玩家留言 跟帖评论
查看更多评论