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. 51Nod - 1405 树的距离之和(树形DP)

    1405 树的距离之和 题意 给定一棵无根树,假设它有n个节点,节点编号从1到n,求任意两点之间的距离(最短路径)之和. 分析 树形DP. 首先我们让 \(1\) 为根.要开两个数组 \(up \ d ...

  2. Out of Sorts II

    问题 E: Out of Sorts II 时间限制: 1 Sec  内存限制: 128 MB提交: 68  解决: 4[提交] [状态] [讨论版] [命题人:] 题目描述 Keeping an e ...

  3. Spring bean初始化以及管理

    在完成bean实例化后,spring会根据配置文件的设定情况对bean 的属性进行初始化, 1.autowire方式 (可查找自动装配对象 但bean中要有相应属性的set方法)这是一个自动装配的机制 ...

  4. Java字符串(String)

    从表面上看,字符串就是双引号之间的数据,例如“微学苑”.“http://www.weixueyuan.net”等.在Java中,可以使用下面的方法定义字符串:    String stringName ...

  5. JSP(待更新)

    1.概念: 所谓JSP就是在HTML中嵌入大量的java代码而已.

  6. 我的一次Postgre数据库Insert 、Query性能优化实践

    一.前言 以前的系统由于表设计比较复杂(多张表,表与表直接有主从关系),这个是业务逻辑决定的. 插入效率简直实在无法忍受,必须优化.在了解了Postgre的Copy,unlogged table 特性 ...

  7. Linux内核分析 - 网络

    http://blog.csdn.net/column/details/network-kernel-yoyo.html

  8. 从let和const谈起

    注册博客园账号也有好些年了,有事没事经常来逛逛,感觉博客园的同学们一直都很活跃,相比国内其他社区来讲,这里的技术氛围很浓,非常适合学习和交流,所以博主我也决定在这里驻扎了,在这里,博主希望能坚持写一些 ...

  9. Kyle 的 iOS 面试题

    1.简单介绍下你对swizzling方法的了解,一般你什么时候使用. 2.有三个对象 A,B,C..:A retain B, B retain C, C retain B..当 A release B ...

  10. docker ubunt镜像中文乱码,文件名问号解决

    一 安装语言包 中文语言包: language-pack-zh-hans 简体中文 language-pack-zh-hans-base language-pack-zh-hant 繁体中文 lang ...