Linux_Rsync远程同步备份服务器

简介: 目录目录Remote Sync同步的类型本地模式远程模式RSync列表模式RSync 服务模式Setup RSync serviceHow to use the rsync commandsinotifyrsync Real-time syncSetup inotifyRemote Sync功能: 1.

目录

Remote Sync

功能
1. 可以镜像保存整个目录树和文件系统
2. 很容易做到保持原来文件的权限,时间,属主,软硬连接等
3. 可使用rcp,ssh等方式来传输文件,也可直接通过socket来进行连接
4. 支持匿名传输
General use for remote backup and backup localhost file into remote host(auto-periodical execute)
Distinction of backup and copy:
1. backup:Update the data.
2. copy:Move all data to other space.
RSync可以实现增量备份,而且可以同步更新数据,实时备份。RSync主机同步网络YUM源,本地局域网同步RSync主机YUM源。

同步的类型

本地模式

将a目录内的文件通过rsync到另一个b目录
example:

rsync -av test /tmp

Attention:
a. /tmp/:不将tmp目录备份,只备份tmp目录下的内容
b. /tmp:将tmp目录及其以下的内容完全备份

远程模式

底层是使用SSH协议
example:

rsync -av /tmp root@GoalHostIP:/root

RSync列表模式

example:

rsync -a IP:cisco

RSync 服务模式:

Rsync同步源、SSH源 –> 备份文件的源主机

Setup RSync service

step1. Create RSync service configuration file by manual
vim /etc/rsyncd.conf

        #RSync configuration file
        #Welcome file
        motd file = /etc/rsyncd.motd
        read>list = yes
        uid=root
        gid=root
        use chroot = no
        max connections = 5
        log file = /var/log/rsyncd.log
        pid file = /var/run/rsyncd.pid
        lock file = /var/run/rsyncd/lock
        #Specify share directory
        [wwwroot]
        path = /var/www/html
        readonly = yes
        auth users = jmilk
        #user authentication file, store userName and password
        secrets file = /etc/rsyncd.db
        comment = rsync directory

step2. Create password file

echo "jmilk:fanguiju" >> /etc/rsyncd.db
chmod 600 /etc/rsyncd.db

step3. Start rsync service

rsync --deamon

How to use the rsync commands

rsync指令选项

    -av  同步并且显示详细信息
    -z     在传输备份是进行压缩
    --delete 将目的位置中有而源位置中没有的文件删除
    --password-file=/etc/server  指定存放密钥对的位置
    -H   保留硬链接

example:

#use rsync source:
rsync -avzH --delete backuper@:ip::wwwroot  /var/www/html  --> ::shareDirectory
#use ssh source in the client:
rsync -avzH root@RSyncServerIP:/syncDirectory    /localhostBackupDirecttory

SSH Source create Key Pair:

ssh-keygen -t rsa
ssh-copy-id root@RSyncServerIP

RSync Source create Key Pair:
vim /etc/rsyncd.conf

RSYNC_PASSWORD="pwd123"

RSync backup:

rsync -avzH -b --backup-dir=old root@SyncServerIP:/syncDirectory    /localhostBackupDirectory
        #old --> 只是备份有修改过的文件到该目录中,并且创建在本地指定的/localostBackupDirectory目录中
        #-b --> backup mode
rsync -avzH -b --backup-dir='date+ "%Y%M%B%H%M%S"' root@SyncServerIP:/syncDirectory    /localhostBackupDirectory #在每次更新后都生成一个只包含修改部分的备份文件
rsync -avzH -b --backup-dir='date+ "%Y%M%B%H%M%S"' --exclude=up root@SyncServerIP:/syncDirectory    /localhostBackupDirectory #将备份目录中包含up的文件或子目录排除不备份

inotify+rsync Real-time sync

inotify机制:监控文件系统的变化
Software:inotofy-tools(安装在RSyncServer)
inotify kernel parameter:

max_queue_events:监控队列大小
max_user_instances:最多监控例数
max_user_watches:每个实例最多的监控个数

Setup inotify

tar zxvf inotify-tools -C /usr/local
cd /usr/local/inotify-tools
./confugure && make && make install
inotifywait -mrq -e modify,create,move,delete  /data/ --exclude=/data/up/
        #wait 持续监控
        #-e     指定监控事件的类型
        #--exclude  过滤不想监控的目录或内容

BUG:编译安装的过程中可能会出现执行以上指令后出现: libinotifytools.so.o:cannot open shared object file error
解决办法:ln -S /usr/local/lib/libinotifytools.so.o /usr/lib64

相关文章
|
16天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
20天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 <<EOF binary put file.txt quit EOF ```
29 4
|
1月前
|
定位技术
GPS北斗卫星同步时钟(时间同步服务器)建设施工部署方案
GPS北斗卫星同步时钟(时间同步服务器)建设施工部署方案
GPS北斗卫星同步时钟(时间同步服务器)建设施工部署方案
|
1月前
|
Linux Shell 网络安全
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
【Shell 命令集合 网络通讯 】Linux 与SMB服务器进行交互 smbclient命令 使用指南
50 1
|
15小时前
|
Linux
如何将一个linux服务器挂载到另外一个linux服务器上
如何将一个linux服务器挂载到另外一个linux服务器上
12 1
|
2天前
|
监控 Linux 网络安全
Linux服务器如何查询连接服务器的IP
【4月更文挑战第15天】Linux服务器如何查询连接服务器的IP
9 1
|
2天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
40 2
|
6天前
|
网络协议 安全 Linux
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
|
12天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1241 8
|
24天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器