通过一个备份归档的脚本演示rsync限速和find如何删除文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/bin/bash # # 2015/04/15 src= 'mysqlbak'
ip= '192.168.1.20'
dest= '/data/backup/mysql/3306/test20'
f_log= '/data/backup/mysql/log/bak_mysql_3306_test20.log'
[ -d $dest ] || mkdir -p $dest
echo "[`date +%F_%T`] rsync mysql slave tar backup file from test20 and remove old one:" >${f_log}
rsync -avzP --bwlimit=50000 ${ip}::${src} /gz ${dest} >>${f_log} 2>&1
rsync -avzP --bwlimit=50000 ${ip}::${src} /log ${dest} >>${f_log} 2>&1
echo "[`date +%F_%T`] finished! 10s later, delete files over 30 days:" >>${f_log}
sleep 10s
find /data/backup/mysql/3306/test20/gz -maxdepth 1 - type f -name "*.tar.gz" -mtime +30 -print >>${f_log} 2>&1
find /data/backup/mysql/3306/test20/gz -maxdepth 1 - type f -name "*.tar.gz" -mtime +30 -delete >>${f_log} 2>&1
find /data/backup/mysql/3306/test20/log -maxdepth 1 - type f -name "*.log" -mtime +30 -print >>${f_log} 2>&1
find /data/backup/mysql/3306/test20/log -maxdepth 1 - type f -name "*.log" -mtime +30 -delete >>${f_log} 2>&1
|
其中test20上的rsyncd.conf的配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[Jack@test20 ~]$ cat /etc/rsyncd .conf
uid = nobody gid = nobody use chroot = no max connections = 50 pid file = /var/run/rsyncd .pid
lock file = /var/run/rsync .lock
log file = /var/log/rsyncd .log
[mysqlbak] path = /data/backup/mysql/3306
read only = yes
list = no hosts allow = 192.168.1.250 hosts deny = * uid = root gid = root
|
本文转自 pcnk 51CTO博客,原文链接:http://blog.51cto.com/nosmoking/1632845,如需转载请自行联系原作者