inotify+rsync
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的更多相关文章
- inotify +rsync进行实时同步
1.安装rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmyum -y install ino ...
- 真正的inotify+rsync实时同步 彻底告别同步慢
真正的inotify+rsync实时同步 彻底告别同步慢 http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用in ...
- 第2章 rsync(二):inotify+rsync详细说明和sersync
本文目录: inotify+rsync 1.1 安装inotify-tools 1.2 inotifywait命令以及事件分析 1.3 inotify应该装在哪里 1.4 inotify+rsync示 ...
- inotify+rsync实现实时同步
第1章 数据实时同步介绍 1.1 什么是实时同步:如何实现实时同步 A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 B. 发现目录中数据产生变化,就利用rsync服务推送到 ...
- inotify+rsync架构实现实时同步
前序 使用inotify+rsync架构实现(文件夹/文件)实时同步, 双机之间需要ssh免密码配置(两步完成ssh免密码登录) 环境 客户端:192.168.137.176 (rsync + ino ...
- 【转】inotify+rsync实现实时同步
[转]inotify+rsync实现实时同步 1.1 什么是实时同步:如何实现实时同步 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 发现目录中数据产生变化,就利用rsync服 ...
- Inotify+rsync实现实时数据同步
使用rsync可以实现数据同步,但是即使使用crontab定时任务最小执行间隔为1分钟,在数据实时性要求比较高场合需使用inotify+rsync实现实时同步 下载inotify wget https ...
- 【转载】inotify+rsync实时同步 解决同步慢问题 (转载备记)
原文地址:http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用inotify+rsync做实时同步,来解决分布式集群文件一致性的问题. ...
- 实时同步inotify+rsync
目的,要求 nfs储存服务器与backup备份服务器,数据同步,万一nfs储存服务器挂了,数据还在 实时同步备份软件服务 1)inotify 实时同步软件 2)sersync 实时同步软件 实时同步原 ...
- inotify+rsync实现实时同步并邮件通知
服务器之间文件实时同步,监控文件的变化,发送邮件通知,并实时同步文件. 由于人工同步多台服务器的文件比较吃力,可以借助这样一套软件,自动化的实现这样的工作. 并且可以事实监控变化发送邮件给系统管理人员 ...
随机推荐
- [BZOJ2460][BJOI2011]元素(线性基)
2460: [BeiJing2011]元素 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2195 Solved: 1119[Submit][Sta ...
- 【bzoj1977】【严格次小生成树】倍增维护链上最大次大值
(上不了p站我要死了,侵权度娘背锅) Description 小 C 最近学了很多最小生成树的算法,Prim 算法.Kurskal 算法.消圈算法等等. 正当小 C 洋洋得意之时,小 P 又来泼小 C ...
- JDBC-登陆功能实现
1.user.java package songyan.jdbc.entity; import java.util.Date; public class User { private int id; ...
- apache mod_speling.so 忽略URL大小写(自动纠错)
apache mod_speling.so 忽略URL大小写(自动纠错) 打开配置文件 httpd.conf 加入 LoadModule speling_module modules/mod_spe ...
- SQL Reverse函数
原文:SQL Reverse函数 Sql sever里面有个自带的reverse函数,这个函数的主要功能是把一个字符产反转.比如对于: select REVERSE('hello,world') 将得 ...
- Ubuntu下安装配置JDK
第一步:下载jdk-7-linux-i586.tar.gz wget -c http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586 ...
- html 打印代码,支持翻页
ylbtech_html_print html打印代码,支持翻页 <html> <head> <meta name=vs_targetSchema content=&qu ...
- eclipse进行Debug的时候,发出“java breakpoint unable to install breakpoint”错误
错误情况图: 问题的解决方法: 直接点击忽略掉:Don't tell me again 来自网上的答案~~ I had the same error message in Eclipse 3.4.1, ...
- Java里日期转换及日期比较大小
1.比较日期的大小: DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//创建日期转换对象hh:mm:ss为 ...
- ES里关于对象的拓展
一.对象类别 在浏览器这样的执行环境中,对象没有统一的标准,在标准中又使用不同的术语描述对象,ES6规范清晰定义了每一个类别的对象,对象的类别如下 1.普通(Ordinary)对象:具有JS对象所有的 ...