shell 备份数据

备份日志

  • 备份/var/log 日志
[root@zabbix-server day6]# more back_log.sh 
#!/bin/bash

date=`date +%Y%m%d`
if [ ! -f /tmp/log-$date.tar.gz ] ; then
   tar -czf /tmp/log-$date.tar.gz /var/log
fi
  • 逻辑备份
[root@zabbix-server day6]# more MysqLdump.sh 
#!/bin/bash

date=$(date +%Y%m%d)
iuser=zabbix
ipass=123456
db=MysqL

if [ ! -f /tmp/$db-$date.sql ] ; then
   MysqLdump -u$iuser --password=$"$ipass" $db > /tmp/$db-$date.sql
fi
  • 物理备份
[root@zabbix-server day6]# more bak_MysqL.sh 
#!/bin/bash
date=`date +%Y%m%d`
db_dir="/var/lib/MysqL"
db="MysqL"

[ ! -d /tmp/$db ] && mkdir /tmp/$db
for i in $(ls $db_dir/$db)
do
  tar -zcf /tmp/$db/$i-$date.tar.gz $db_dir/$db/$i
done
  • 差异备份

inotify+rsync

[root@zabbix-server day6]# more isync.sh
#!/bin/bash
#备份源数据
FROM_DIR="/var/www/html/"
#
RSYNC_CMD="rsync -az --delete $FROM_DIR \
#备份到207下/var/www/html下 
root@192.168.4.207:/var/www/html"
#实时差异备份,检查目录有a,d,m那么执行copy命令
while inotifywait -rqq -e modify,move,create,delete,attrib $FORM_DIR
do
   $RSYNC_CMD
done &

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本