使用Rsync备份数据
2008年12月14日
没有评论
经历了硬盘数据全没了的痛苦,痛定思痛,作好每日或更短时间的备份功作犹为重要,真正做到有备无患。
- 准备:
- 系统环境:Debian 4.0 (其它linux大同小异)
- 需要权限:root
- 安装:
apt-get install rsync
- 配置服务端:
- 建立配置文件:/etc/rsyncd.conf
Debian4下rsyncd.conf不直接提供,那就新建一个vi /etc/rsyncd.conf
输入
uid = nobody gid = nogroup use chroot = no max connections = 4 pid file = /var/run/rsync.pid lock file = /var/run/rsync.lock log file=/var/log/rsync.log #备份的模块名 [website] path = /var/www comment = backup ignore errors read only = true list = false #备份用户名 auth users = test #帐号密码文件 secrets file = /etc/rsyncd.secrets
- 建立帐号文件/etc/rsyncd.secrets
vi /etc/rsyncd.secrets
输入
#用户名:密码 test:test
- 更改rsyncd.secrets的权限为只读
chmod 0400 /etc/rsyncd.secrets
- 配置inetd
vi /etc/inetd.conf
添加
rsync stream tcp nowait root /usr/bin/rsync rsync --daemon
- 重启inetd
/etc/init.d/openbsd-inetd restart
- 建立配置文件:/etc/rsyncd.conf
- 配置客户端
- 建立密码文件password
echo 'test'>password
- 同步数据
rsync -vzrtopg --progress --password-file=password test@服务器IP::website /var/www
同步服务器IP的website到目录/var/www
-v –verbose #输出调试信息
-z –compress #压缩数据
-r –recursive #递归目录,通俗讲就是包括所有子目录
-t –times #保持时间
-o –owner #保持所有者
-p –permission #保持permission
-g –group #保持组
- 建立密码文件password
近期评论