用批处理备份交换机的日志文件

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

批处理文件内容如下:

@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 =====复制到金山快盘=====
copy *.rar E:\SQLBak\SyslogBAK
del *.rar


————————————————
版权声明:本文为CSDN博主「CoolWater」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/c00lwater/article/details/13024051

posted on 2020-04-26 17:22  cxyc005  阅读(534)  评论(0编辑  收藏  举报

导航