当前位置:网站首页>rsync做文件备份
rsync做文件备份
2022-06-24 07:03:00 【一个不靠谱的程序员】
rsync
rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。
可以镜像保存整个目录树和文件系统。
可以很容易做到保持原来文件的权限、时间、软硬链接等等。
无须特殊权限即可安装。
快速:第一次同步时 rsync 会复制全部内容,但在下一次只传输修改过的文件。rsync 在传输数据的过程中可以实行压缩及解压缩操作,因此可以使用更少的带宽。
安全:可以使用scp、ssh等方式来传输文件,当然也可以通过直接的socket连接。
支持匿名传输,以方便进行网站镜象。
rsync安装
- 下载 (2018年9月25日13:52:23 最新版本为3.1.3)
wget https://download.samba.org/pub/rsync/src/rsync-3.1.3.tar.gz - 解压
tar -xvf rsync-3.1.3.tar.gz - 进入解压后的目录
- 配置
./configure --prefix=/usr/local/rsync/ - 编译
make - 安装
make install
配置服务端conf
vi /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
uid = root
gid = root
use chroot = false #是否限定在该目录下,默认为true,当有软连接时,需要改为fasle,如果为true就限定为模块默认目录
read only = yes #是否为只读,如果是no的话,客服端推送给服务端的时候不成功,这时候要改成yes
#limit access to private LANs
hosts allow= #客户端地址
hosts deny=*
max connections = 5
#This will give you a separate log file
log file = /mnt/log/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 = 900
ignore nonreadable = yes
dont compress = .gz .tgz .zip .z .Z .rpm .deb .bz2
[test]
path = /home/back
comment = files backup
list=no
ignore errors
auth users = root
secrets file = /usr/local/rsync/rsyncd.secrets
#exclude =
配置服务端用户密码文件
vi rsyncd.secrets
这里只要和配置文件里的【test】模块里的secrets file对应的配置项一致即可
内容的格式是 用户名:密码
例如root:root123
修改用户密码文件的权限
chmod 600 /usr/local/rsync/rsyncd.secrets
启动服务端程序,以守护进程模式运行
进入bin目录,执行./rsync --daemon即可启动
可以通过查看端口号占用来确认启动成功netstat -antp|grep 873
关于重启服务端守护进程方式
直接kill掉进程然后重新启动即可,就是如此暴力
客户端进行同步测试
rsync -vzrtlopg --progress [email protected]服务端IP::模块名 /path/ --password-file=/etc/rsyncd.passwd
命令解析:
-v, --verbose 详细模式输出。
-z, --compress 对备份的文件在传输时进行压缩处理。
-r, --recursive 对子目录以递归模式处理。
-t, --times 保持文件时间信息。
-l, --links 保留软链结。
-o, --owner 保持文件属主信息。
-p, --perms 保持文件权限。
-g, --group 保持文件属组信息。
因为我们做的是冗余主备,因此千万不要加 --delete 删除那些DST中SRC没有的文件。
如果是需要做完全同步,则需要加上 --delete命令 , 即服务端删除的文件,客户端也会进行删除。
定时备份
将上述命令加入计划任务,即可实现每天的增备。
踩坑指南
1.守护模式启动必须得加上 --daemon参数
2.如果客户端的密码也是存在文件里的,如上所示,注意客户端的密码文件和服务端密码文件不一样,客户端这里不需要用户名,只要密码就行。
边栏推荐
猜你喜欢

5 minutes, excellent customer service chat handling skills

【关于运维和网工的差别,一文说透】

ZUCC_ Principles of compiling language and compilation_ Experiment 03 getting started with compiler

Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022

成为IEEE学生会员

ZUCC_ Principles of compiling language and compilation_ Experiment 02 fsharp Ocaml language

ZUCC_编译语言原理与编译_实验08 语法分析 LR 分析

OpenCV to realize the basic transformation of image

独立站运营中如何提升客户留存率?客户细分很重要!

Pat 1157: school anniversary
随机推荐
Base64编码详解及其变种(解决加号在URL变空格问题)
MAYA重新拓布
Three ways to uninstall Symantec Endpoint Protection Symantec
PHP代码加密的几种方案
Markdown 实现文内链接跳转
"Adobe international certification" Photoshop software, about drawing tutorial?
[acnoi2022] not a structure, more like a structure
5 minutes, excellent customer service chat handling skills
One development skill a day: how to establish P2P communication based on webrtc?
Detailed explanation of etcd backup and recovery principle and actual record of stepping on the pit
Five level classification of loans
Battle history between redis and me under billion level traffic
How to handle the problem that calling easycvr address integration cannot be played through easyplayer player?
After interviewing and tutoring several children, I found some problems!
QT writing security video monitoring system 36 onvif continuous movement
【无标题】
pyQt 中 QMenu 响应
io模型初探
中国芯片独角兽公司
jwt(json web token)