rsync从linux到linux的文件同步备份

运维 系统运维
需要备份文件的服务器(服务器端):192.168.1.201 (RHEL 5).接收备份文件的服务器(客户端):192.168.1.202 (CENTOS 5)

一、环境
需要备份文件的服务器(服务器端):192.168.1.201 (RHEL 5)
接收备份文件的服务器(客户端):192.168.1.202 (CENTOS 5)

二、安装配置
1.服务器端的配置
A、采用系统默认安装的rsync 编辑/etc/rsyncd.conf文件,如果没有则新建一个。
vi /etc/rsyncd.conf
#[globale]
strict modes= yes  #check passwd file
port= 873 #default port
logfile= /var/log/rsyncd.log
pidfile= /var/run/rsyncd.pid
max connections= 4
#[modules]
[testlink]   #备份模块
uid= root
gid= root
path= /usr/local/apache/htdocs/testlink/upload_area  #要备份的目录
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt
[bugfree]         #备份模块
uid= root
gid= root
path= /usr/local/apache/htdocs/bugfree/BugFile         #要备份的目录
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt
[redmine]   #备份模块
uid= root
gid= root
path= /usr/local/redmine-0.8.1/files       #要备份的目录
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt

B、 添加一个密码文件
vi /etc/rsyncd.scrt
内容如下:
wwyhy:123456  #(自己设置)

C、改变权限为600
chmod 600 /etc/rsyncd.scrt

D、启动服务(如开有防火墙请允许873端口通过)
rsync --daemon --config=/etc/rsyncd.conf &

2.配置客户端
客户端我则自己编译安装的rsync-3.0.3.tar.gz的
A、安装:
tar -zxvf rsync-3.0.3.tar.gz
cd rsync-3.0.3
./configure
make
make install
B、添加密码文件
vi /etc/rsyncd.scrt (没有就新建)
内容如下:
wwyhy:123456 (文件与客户端文件内容一样)
C、改文件权限为600
chmod 600 /etc/rsyncd.scrt

三、开始备份
可以在客户端通过man rsync指令来查看备份指令
我们用脚本来自动执行备份
列:rsync -avz --password-file=密码文件路径 username@需要备份的主机IP::备份里的模块名称
接收备份文件的路径
在/root建一个脚本文件
vi backup

添加内容如下:
#1.192.168.1.201上的testlink附件备份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::testlink
/home/wangwei/testlink/upload_area
#2.192.168.1.201上的bugfree附件备份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::bugfree
/home/wangwei/bugfree/BugFile
#3.192.168.1.201上的redmine附件备份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::redmine
/home/wangwei/redmine-0.8.1/files

chmod u+x backup

每晚2.30自动执行
vi /etc/crontab

30 2 * * * root /root/backup


 

【编辑推荐】

  1. 嵌入式系统Linux内核开发实战指南
  2. Linux设备驱动开发详解
  3. Linux系统***实践工具:命令行技术
责任编辑:张燕妮 来源: 中国IT实验室
相关推荐

2017-03-01 12:19:17

rsync Linux系统

2009-11-30 10:05:28

Linuxrsync同步

2010-09-14 09:15:03

RsyncLinux备份远程数据同步

2021-06-09 08:05:02

Linux 备份数据

2021-06-18 10:28:56

Linuxrsync命令

2019-09-02 07:53:09

Linuxrsync服务器

2023-01-31 08:34:19

2012-02-29 00:49:06

Linux学习

2020-12-17 08:14:30

Linuxrsync备份

2011-10-09 09:26:04

ubuntursync服务器

2017-06-29 09:28:37

OracleMariaDB复制

2013-12-18 13:30:19

Linux运维Linux学习Linux入门

2021-12-20 14:22:07

Linux打印文件

2013-09-16 16:20:55

自动备份Dropbox

2010-11-22 09:36:37

Perl脚本SolarisLinux

2017-03-25 20:30:15

2018-09-19 12:08:04

Linux服务器数据

2020-09-24 08:45:10

React架构源码

2014-08-14 10:52:49

windowslinux

2018-11-08 10:13:28

Rsync服务器备份
点赞
收藏

51CTO技术栈公众号