#!/bin/bash
service rsyslog stop
BackupPath=/Logback/
LogFile=/Logback/back.log
DBPath=/var/log/switch
Date=$(date +%y%m%d)
File=/Logback/log_bak$Date.tgz
NewFile=”$BackupPath”log_bak$Date.tgz
if [ ! -d “$BackupPath” ]; then
mkdir $BackupPath
fi
echo “——————————————-” >> $LogFile
echo $(date +”%y-%m-%d %H:%M:%S”) >> $LogFile
echo “————————–” >> $LogFile
tar cPzvf $NewFile $DBPath >> $LogFile 2>&1
if [ -f “$File” ]; then
rm -rf /var/log/switch/*
else
echo “文件不存在,现在开始备份!” >> $LogFile
tar cPzvf $NewFile $DBPath >> $LogFile
fi
echo “日志备份成功!” >> $LogFile
service rsyslog start
chmod -R 755 /var/log/switch/
echo “注意:备份文件解压路径为’/var/log/switch/ ‘,解压时注意防止覆盖未备份日志文件!” >> $LogFile
mail -s “日志备份成功!” liufengnian@ghnovo.com < /Logback/back.log