backup_to_rsync.sh
#!/bin/bash
#source function library
. /etc/init.d/functions
rsync_host=rsync.etiantian.org

#define variables
IP=$(ifconfig eth1|awk -F '[ :]+' 'NR==2 {print $4}')
Path="/backup/$IP"
TIME=`/bin/data +%F`
BackupFile=/server/scripts/backuplist

[ ! -d $Path ] && mkdir -p $Path
[ ! -f $BackupFile ] && [
echo "Please give me $BackupFile"
exit 1
]

function Msg(){
if [ $? -eq 0 ];then
action "$*" /bin/true
else
action "$*" /bin/false
fi
}

# Backup config files
tar zcfh $Path/conf_${TIME}.tar.gz `cat $BackupFile` &>/dev/null
Msg 'Backup config files'

#Make a flag for backup
find $Path -type f -name "*${TIME}.tar.gz"|xargs md5sum >$Path/flag_$TIME 2>/dev/null
Msg 'Make a flag for backup'

# Send backup to backup server
rsync -az $Path rsync_backup@${rsync_host}::backup --password-file=/etc/rsync.password &>/dev/null
Msg 'Send backup to backup server'

#Delete backup a week ago
find ${Path} -type f -name "*.tar.gz" -mtime +7 | xargs rm -f &>/dev/null
Msg 'Delete backup a week ago'

echo -e "#backup data\n00 00 * * * /bin/sh /server/scripts/backup_to_rsync.sh &>/dev/null" >> /var/spool/cron/root

/server/scripts/rsync.sh
#!/bin/bash
###################
# file name : rsync.sh
# description : install and config rsync server
###################
. /etc/init.d/functions

function Msg(){
if [ $? -eq 0 ];then
action "$*" /bin/ture
else
action "$*" /bin/false
fi
}

function rsyncd_conf(){
cat >/etc/rsyncd.conf<<EOF
sync server
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
##################
[backup]
comment = back server by
path = /backup
EOF
Msg "rsyncd_conf"
}

function rsync(){
useradd -u 666 rsync -M -s /sbin/nologin
[ ! -d /backup ] && mkdir -p /backup
[ ! -d /server ] && mkdir -p /server/tools
[ ! -d /server/scripts ] && mkdir -p /server/scripts
chown -R rsync.rsync /backup
echo "rsync_backup:123456" > /etc/rsync.password &&\
chmod 600 /etc/rsync.password
# 判断rsync是否启动
[ ! -f /server/scripts/rsyncd ] && {
echo "/server/scripts/rsyncd is not exist,error."
exit 2
}
\cp /server/scripts/rsyncd /etc/init.d/
chmod 755 /etc/init.d/rsyncd
netstat -ntulp | grep "873"
if [ $? -eq 0 ];then
echo "rsync is running" > /dev/null
else
/etc/init.d/rsyncd restart
fi
/sbin/chkconfig --add rsyncd
/sbin/chkconfig rsyncd on
Msg "rsync"
sleep 1
}

function postfix(){
if [ `grep "oldboyedu" /etc/mail.rc|wc -l` -eq 0 ];then
/bin/cp /etc/mail.rc /etc/mail.rc.$RANDOM
echo -e "set from=oldboyedu@163.com smtp=smtp.163.com\nset smtp-auth-user=oldboyedu smtp-auth-password=oldboy123 smtp-auth=login" >> /etc/mail.rc
/etc/init.d/postfix restart
else
echo "postfix is not need to config it."
fi
sleep 1
}

function crond_check(){
[ `crontab -l | grep "check.sh"| wc -l` -eq 0 ] &&{
echo -e "#check backup\n00 08 * * * /bin/sh /server/scripts/check.sh >/dev/null 2>&1" >> /var/spool/cron/root
crontab -l
sleep 2
} || {
echo "check.sh cron is exist, no config"
}
}
function main(){
rsyncd_conf
rsync
postfix
crond_check
}
main

#!/bin/bash
# filename : rsyncd
# description :
#chkconfig: 2345 56 24
. /etc/init.d/functions
RETVAL=0
prog="rsync"
#check if rsync is already running
start(){
if [ ! -f /var/run/rsyncd.pid ];then
/usr/vin/rsync --daemon --config=/etc/rsyncd.conf
fi
RETVAL=$?
sleep 1
if [ $RETVAL -eq 0 ];then
action "starting $prog ..." /bin/true
else
action "starting $prog ..." /bin/false
fi
return $RETVAL
}

stop(){
killproc /usr/sbin/rsync
RETVAL=$?
sleep 1
if [ $RETVAL -eq 0 ];then
rm -f /var/run/rsyncd.pid
action "stopped $prog ..." /bin/true
else
action "stopped $prog ..." /bin/false
fi
}
restart(){
$0 stop
$0 start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage:$0 {start|stop|restart}"
exit 1
esac

#!/bin/bash
# filename : check_bak.sh
DIR=/backup
TIME=`/bin/date +%F`
log=/tmp/$TIME-check.log

[ -d $DIR ] && {
find $DIR -type f -name "flag_$TIME" |xargs md5sum -c >$log 2>/dev/null
mail -s "$(date +%F_%T) back check result" 12343qq.com <&log
}

#!/bin/bash
# filename : inotifyd.sh
[ ! -f /etc/yum.repos.d/epel.repo ] && \
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
if [ $? -eq 0 -a `rpm -qa inotify-tools|wc -l` -ne 1 ];then
yum -y install inotify-tools
fi
inotify=/usr/bin/inotifywait
rsync_host=rsync.etiantian.org
[ ! -d /data0 ] && mkdir /data0
$inotify -mrq --format '%w%f' -e create,close_write,delete /data0 \
| while read file
do
cd / &&
rsync -az /data0 --delete rsync_backup@${rsync_host}::backup/ --password-file=/etc/rsync.password
done

inotify+rsync的更多相关文章

  1. inotify +rsync进行实时同步

    1.安装rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmyum -y install ino ...

  2. 真正的inotify+rsync实时同步 彻底告别同步慢

    真正的inotify+rsync实时同步 彻底告别同步慢       http://www.ttlsa.com/web/let-infotify-rsync-fast/     背景 我们公司在用in ...

  3. 第2章 rsync(二):inotify+rsync详细说明和sersync

    本文目录: inotify+rsync 1.1 安装inotify-tools 1.2 inotifywait命令以及事件分析 1.3 inotify应该装在哪里 1.4 inotify+rsync示 ...

  4. inotify+rsync实现实时同步

    第1章 数据实时同步介绍 1.1 什么是实时同步:如何实现实时同步 A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 B. 发现目录中数据产生变化,就利用rsync服务推送到 ...

  5. inotify+rsync架构实现实时同步

    前序 使用inotify+rsync架构实现(文件夹/文件)实时同步, 双机之间需要ssh免密码配置(两步完成ssh免密码登录) 环境 客户端:192.168.137.176 (rsync + ino ...

  6. 【转】inotify+rsync实现实时同步

    [转]inotify+rsync实现实时同步 1.1 什么是实时同步:如何实现实时同步 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 发现目录中数据产生变化,就利用rsync服 ...

  7. Inotify+rsync实现实时数据同步

    使用rsync可以实现数据同步,但是即使使用crontab定时任务最小执行间隔为1分钟,在数据实时性要求比较高场合需使用inotify+rsync实现实时同步 下载inotify wget https ...

  8. 【转载】inotify+rsync实时同步 解决同步慢问题 (转载备记)

    原文地址:http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用inotify+rsync做实时同步,来解决分布式集群文件一致性的问题. ...

  9. 实时同步inotify+rsync

    目的,要求 nfs储存服务器与backup备份服务器,数据同步,万一nfs储存服务器挂了,数据还在 实时同步备份软件服务 1)inotify 实时同步软件 2)sersync 实时同步软件 实时同步原 ...

  10. inotify+rsync实现实时同步并邮件通知

    服务器之间文件实时同步,监控文件的变化,发送邮件通知,并实时同步文件. 由于人工同步多台服务器的文件比较吃力,可以借助这样一套软件,自动化的实现这样的工作. 并且可以事实监控变化发送邮件给系统管理人员 ...

随机推荐

  1. Js 利用正则表达式和replace函数获取string中所有被匹配到的文本

    js的replace函数除了替换文本以外还有获取所有被正则表达式匹配到的文本的功能.这里以一个简单的案例来作为演示. 利用正则查找出所有被两个花括号包裹的字符串: var str = '<div ...

  2. 51nod 1094 和为k的连续区间【前缀和/区间差/map】

    1094 和为k的连续区间 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 一整数数列a1, a2, ... , an(有正有负),以及另一个整数k ...

  3. navicat连接MySQL8.0.11提示2059错误

    错误原因:mysql加密规则的改变: mysql加密规则:mysql_native_password      mysql8之前的版本   caching_sha2_password     mysq ...

  4. Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细心讲解)

    layout: post title: Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细 ...

  5. Apache CXF实战之四 构建RESTful Web Service

    Apache CXF实战之一 Hello World Web Service Apache CXF实战之二 集成Sping与Web容器 Apache CXF实战之三 传输Java对象 这篇文章介绍一下 ...

  6. Trapping Rain Water (Bar Height) -- LeetCode

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  7. thinkphp Auth认证类 比RBAC更好的权限认证方式(Auth类认证)

    thinkphp Auth认证类 比RBAC更好的权限认证方式(Auth类认证)    Auth 类已经在ThinkPHP代码仓库中存在很久了,但是因为一直没有出过它的教程, 很少人知道它, 它其实比 ...

  8. SQL获取当月天数的几种方法

    原文:SQL获取当月天数的几种方法 日期直接减去int类型的数字 等于 DATEADD(DAY,- 数字,日期) 下面三种方法: 1,日期加一个月减去当前天数,相当于这个月最后一天的日期.然后获取天数 ...

  9. ife2015-task2-4-5

    task2-4.html<!DOCTYPE html><html><head lang="en"> <meta charset=" ...

  10. Linux中常使用的宏判断的几个例子

    示例一 #ifdef CONFIG_XX1 ...... #endif 示例二 #ifdef CONFIG_XX1 ...... #else ...... #endif 示例三 #if defined ...