服务端:
1) vim /etc/rsyncd.conf
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 10.32.20.253
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = no
read only = no
#limit access to private LANs
hosts allow=10.32.20.0/255.255.0.0 172.16.3.0/255.255.0.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd.motd
#This will give you a separate log file
log file = /tmp/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
#OA backup
[backup]
path = /home/backup
#list=yes
#ignore errors
#auth users = root
#secrets file = /etc/rsyncd.secrets
#otrs
[otrsapp]
path = /mnt/share/otrsapp
2)vim /etc/rsyncd.motd
+++++++++++++++++++++++++++++++++++++++
OA/OTRS/ rsync services on 10.32.20.253
2002------2016
+++++++++++++++++++++++++++++++++++++++
3)vim /etc/rsyncd.secrets
root:omrMvi+CRLO+CeViFn
客户端备份用的脚本:
#!/bash/bin
# Otrsapp backup
#Ip=$(ifconfig eth0 | awk -F '[ :]+' 'NR==2 {print $4}')
#Path="/backup/$Ip"
#[ ! -d $Path ] && mkdir $Path -p
# SYSTEM_DIR=/root/ufsoft
date=`date +%F`
#days=7
# del
find /backup -type f -name "*.tar.gz" -mtime +0 | xargs rm -rf
# backup
cd /opt
tar -zcf /backup/otrs-$date.tar.gz otrs
# to backup server
rsync -avz /backup/otrs-$date.tar.gz root@10.32.20.253::otrsapp --password-file=/etc/rsyncd.secrets
3)在客户端查看服务器端的列表
rsync root@10.32.20.253::otrsapp --password-file=/etc/rsyncd.secrets
4)yongyou
vim /root/ncbackup.sh
#!/bash/bin
# yongyouapp backup
BACKUP_DIR=/mnt/share/yougyouapp
# SYSTEM_DIR=/root/ufsoft
date=`date +%Y%m%d`
days=6
tar -zcf $BACKUP_DIR/ufsoft.$date.tar.gz /root/ufsoft
find /mnt/share -type f -name "*.tar.gz" -mtime +$days | xargs rm -rf
5)guide
vim remotebackupguide.sh
#!/usr/local/bin/sshpass
sshpass -f /backups/pwd.txt scp /backups/guideAppWeek`date +%w`.tar.gz root@10.32.20.253:/mnt/share/guide/
sshpass -f /backups/pwd.txt scp /backups/guideDataWeek`date +%w`.tar.gz root@10.32.20.253:/mnt/share/guide/
6)zabbix
vim /data/backup/databackup.sh
# date:20160824
# backup for zabbix files
date=`date +%Y%m%d`
tar zcf /data/backup/appbackup/zabbix.$date.tar.gz /usr/local/zabbix
tar zcf /data/backup/appbackup/zabbix_html.$date.tar.gz /var/www/html/zabbix
sshpass -f /data/backup/pwd.txt scp /data/backup/appbackup/zabbix.$date.tar.gz root@10.32.20.253:/mnt/share/zabbix/
sshpass -f /data/backup/pwd.txt scp /data/backup/appbackup/zabbix_html.$date.tar.gz root@10.32.20.253:/mnt/share/zabbix/
find /data/backup/appbackup -name "*.tar.gz" -type f -mtime +6 -exec rm {} ;
安装:[root@backup ~]
# yum install rsync
添加一个控制脚本:[root@backup ~]
# vim /etc/init.d/rsync
#!/bin/bash
#this script for start|stop rsync daemon service
#date:2012/2/13
status1=$(
ps
-ef |
egrep
"rsync --daemon.*rsyncd.conf"
|
grep
-
v
'grep'
)
pidfile=
"/var/run/rsyncd.pid"
start_rsync=
"rsync --daemon --config=/etc/rsyncd.conf"
function
rsyncstart() {
if
[
"${status1}X"
==
"X"
];
then
rm
-f $pidfile
${start_rsync}
status2=$(
ps
-ef |
egrep
"rsync --daemon.*rsyncd.conf"
|
grep
-
v
'grep'
)
if
[
"${status2}X"
!=
"X"
];
then
echo
"rsync service start.......OK"
fi
else
echo
"rsync service is running !"
fi
}
function
rsyncstop() {
if
[
"${status1}X"
!=
"X"
];
then
kill
-9 $(
cat
$pidfile)
status2=$(
ps
-ef |
egrep
"rsync --daemon.*rsyncd.conf"
|
grep
-
v
'grep'
)
if
[
"${statusw2}X"
==
"X"
];
then
echo
"rsync service stop.......OK"
fi
else
echo
"rsync service is not running !"
fi
}
function
rsyncstatus() {
if
[
"${status1}X"
!=
"X"
];
then
echo
"rsync service is running !"
else
echo
"rsync service is not running !"
fi
}
function
rsyncrestart() {
if
[
"${status1}X"
==
"X"
];
then
echo
"rsync service is not running..."
rsyncstart
else
rsyncstop
rsyncstart
fi
}
case
$1
in
"start"
)
rsyncstart
;;
"stop"
)
rsyncstop
;;
"status"
)
rsyncstatus
;;
"restart"
)
rsyncrestart
;;
*)
echo
echo
"Usage: $0 start|stop|restart|status"
echo
esac
[root@backup ~]
# chmod a+x /etc/init.d/rsync
[root@backup ~]
# service rsync restart
rsync是类unix系统下的数据镜像备份工具——remote sync。
安装:
1
|
[root@backup ~] # yum install rsync |
(1)添加一个控制脚本:
1
|
[root@backup ~] # vim /etc/init.d/rsync |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/bin/bash #this script for start|stop rsync daemon service #date:2012/2/13 status1=$( ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep - v 'grep' ) pidfile= "/var/run/rsyncd.pid" start_rsync= "rsync --daemon --config=/etc/rsyncd.conf" function rsyncstart() { if [ "${status1}X" == "X" ]; then rm -f $pidfile ${start_rsync} status2=$( ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep - v 'grep' ) if [ "${status2}X" != "X" ]; then echo "rsync service start.......OK" fi else echo "rsync service is running !" fi } function rsyncstop() { if [ "${status1}X" != "X" ]; then kill -9 $( cat $pidfile) status2=$( ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep - v 'grep' ) if [ "${statusw2}X" == "X" ]; then echo "rsync service stop.......OK" fi else echo "rsync service is not running !" fi } function rsyncstatus() { if [ "${status1}X" != "X" ]; then echo "rsync service is running !" else echo "rsync service is not running !" fi } function rsyncrestart() { if [ "${status1}X" == "X" ]; then echo "rsync service is not running..." rsyncstart else rsyncstop rsyncstart fi } case $1 in "start" ) rsyncstart ;; "stop" ) rsyncstop ;; "status" ) rsyncstatus ;; "restart" ) rsyncrestart ;; *) echo echo "Usage: $0 start|stop|restart|status" echo esac |
(2)给脚本设置可执行权限:
1
|
[root@backup ~] # chmod a+x /etc/init.d/rsync |
(3)启动与重启:
启动命令:
1
|
[root@backup ~] # service rsync start |
重启命令:
1
|
[root@backup ~] # service rsync restart |
或者可以停止后再次启动:
1
2
|
[root@backup ~] # service rsync stop [root@backup ~] # service rsync start |