File backup available tool rsync

Rsync usage guide


1. Backup in the window environment

1. Server side

Open https://devops.5ul.cn/download/ in the browser , and download rsync.zip to the local

Unzip and install

Unzip it, double-click the application. Choose OK all the way to the next step.

The picture shows that the installation is complete.

rsync configuration file

After installation, edit C:/program files(x86)/icw/rsync.conf

Modify to the following configuration:

use chroot = false
strict modes = false
hosts allow = 10.13.1.4   //对方ip地址
log file = rsyncd.log
port = 20003    //不设置默认为873
[wwwroot]
path = /cygdrive/d/wwwroot
read only = true
transfer logging = yes
uid = 0
gid = 0
  • use chroot

  • Whether to lock the root directory before transmission, yes yes, no no. rsync for added security, the default value is yes.

  • hosts allow

  • Clients that are allowed to connect. Fill in the rsync client address according to the actual situation, and separate multiple ips with .

  • port
    specifies the listening port.

  • log file

  • Log files, by default in the rsync installation directory.

  • [wwwroot]

  • module name

  • path

  • Path. The writing method of the path is fixed, and /cygdrive/ is unchanged, only need to modify the following parameters. For example, the D:\wwwroot\ directory of Windows is written as /cygdrive/d/wwwroot

  • read only

  • Whether it is read-only. As a server, it is recommended to enable it.

  • transfer logging

  • Log during transmission. It is recommended to enable

  • uid and gid

  • Specify user id and group id. 0 means anonymous.

policy restrictions
disable user

During this period, rsync will create a user and register the service to log in as this user. Due to the intranet transmission and the configuration of read-only permissions, the service is configured as anonymous access.

Open Computer Management, find Users and Groups, and disable the user.

firewall

Open the windows firewall, and let the port parameters specified in the above configuration file be released one by one. And only allow client ip access

service configuration
boot up

Find the RsyncServer in the service item and set it to start automatically at boot

Modify login options

找到该服务, 右键将 登陆身份 设置为 本地系统系统账户

启动服务

右键启动服务. 如果有报错信息, 检查日志文件.

2、客户端

    • Linux

开始前的准备
  • 查看端口是否可达

nc -zvw3 10.13.1.58 20003
  • 安装 rsync

yum install -y rsync
同步数据
rsync -avzP --port=20003  [email protected]::wwwroot /data/vhost-bak/70-58/bak-9-07-09_18
将服务端 wwwroot 模块下所配置的目录递归同步到 /data/vhost-bak/70-58/bak-9-07-09_18 目录下.
  • -a 表示以递归方式传输文件,并保持所有文件属性

  • -z 传输时压缩

  • -v 详细输出

  • -P 显示实时传输速率等状态

图为正在同步数据.

    • windows

  • 下载客户端

https://devops.5ul.cn/download/cwrsync_6.2.5_x64_free.zip
  • 下载完解压. 进入到目的备份目录

cd E:\tmp

E:\download\cwrsync_6.2.5_x64_free\bin\rsync.exe -avP --port=20003 10.11.1.131::wwwroot .
windows下rsync直接指定目的目录会有问题. 所以 powershell 要先进入到 目的备份目录, 再执行备份命令
  • 开始备份

  • 备份完成

二、Linux环境下备份

服务端使用

安装
yum install -y rsync
配置
cat > /etc/rsync.conf<<EOF
use chroot = false
strict modes = false
hosts allow = 10.13.1.4
log file = rsyncd.log
port = 20003
[wwwroot]
path = /data/wwwroot
read only = true
transfer logging = yes
uid = 0
gid = 0
EOF
  • 该文件与上文 windows的配置无异.

开启服务端
  • 守护进程

服务端已守护进程的方式启动, 默认会找 /etc/rsync.conf 文件. 如果不是默认的该文件, 需要使用 --config=> <rsync_conf_file> 指定配置文件.
rsync --daemon --config=/etc/rsync.conf
  • 查看进程及端口

ps aux | grep rsync
root       336  0.0  0.0 114856   392 ?        Ss   10:51   0:00 rsync --daemon --config=/etc/rsyncd.conf


netstat -antpl | grep rsync
tcp        0      0 0.0.0.0:20003           0.0.0.0:*               LISTEN      336/rsync
tcp6       0      0 :::20003                :::*                    LISTEN      336/rsync

服务端配置完毕. 记得防火墙放行对应端口.

客户端

安装
yum install -y rsync
使用rsync端口同步
rsync -avP --port=20003 10.1.1.1:/wwwroot .
基于ssh认证同步
rsync -avP -e "ssh -p 20002" [email protected]:/wwwroot .
使用 -e "ssh -p 20002" 选项指定ssh端口, 不加该选项即使用22端口.

Guess you like

Origin blog.csdn.net/qq_31972901/article/details/128805500