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

来源:互联网 发布:hr面试java常问的问题 编辑:程序博客网 时间:2024/05/29 10:20
  华为交换机开启日志文件传送功能,发送到某服务器,现在需将收集的日志文件定期打包备份到金山快盘,写了一个批处理,跑在计划任务里。


日志文件如下图所示


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


批处理文件内容如下:

@echo offcd /d E:\LogFilesset CurMonth=%date:~5,2%set LastMonth=00set Year=%date:~0,4%set /a LastYear=%Year%-1echo 当前年份:%Year%echo 当前月份:%CurMonth%REM =====设定需备份的月份=====if %CurMonth%==01 set LastMonth=12if %CurMonth%==02 set LastMonth=01if %CurMonth%==03 set LastMonth=02if %CurMonth%==04 set LastMonth=03if %CurMonth%==05 set LastMonth=04if %CurMonth%==06 set LastMonth=05if %CurMonth%==07 set LastMonth=06if %CurMonth%==08 set LastMonth=07if %CurMonth%==09 set LastMonth=08if %CurMonth%==10 set LastMonth=09if %CurMonth%==11 set LastMonth=10if %CurMonth%==12 set LastMonth=11echo 上月份:%LastMonth%echo 去年年份:%LastYear%REM =====用RAR的命令行进行打包压缩=====REM dir Syslog%Year%-%LastMonth%*.txtREM echo Syslog_%Year%-%LastMonth%.rarREM dir Syslog%LastYear%-%LastMonth%*.txtREM echo Syslog_%LastYear%-%LastMonth%.rarif %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\SyslogBAKdel *.rar

恩,果然CSDN博客对批处理和脚本的支持好多了,爽。

原创粉丝点击