2

Lsync 同步软件的运用

 9 months ago
source link: https://bajie.dev/posts/20231208-lsync/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Lsync 同步软件的运用

2023-12-08 2 分钟阅读

公司使用智齿的机器崩了,要做数据迁移。

由三台老机器迁移到三台新kvm机器

我们需要把其中一台34.38的的东西实时同步两份,一份到30.18的glusterfs,一份到34.41的/data

同时也要注意30.18的GFS中已经有两个虚机文件,32.6和34.38的qcow2

所以lsync务必要小心,不能删除已有文件

172.18.34.38上面的lsyncd.conf如下,同步到两个目的地: 注意下面的参数:

  1. maxProcesses = 2 # 本机用于rsync的进程数

  2. delete = ‘running’ # 只删除lsync启动之后删除的文件,目的文件夹中原有的文件保存

  3. exclude = “upload” # 第二个同步中排除的目录,注意这里是匹配全路径中的部分字串,upload 可以匹配到 /data/new/chatmsg/upload/allajl.jpg,就upload目录下文件大,所以把它排除。**这里的规则是和rsync中exclude的写法不同的!!!**只取路径中的upload字串就可以排除。

----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
-- 
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

settings {
    logfile = "/var/log/lsyncd/lsyncd.log",
    statusFile = "/var/log/lsyncd/lsyncd-status.log",
    statusInterval = 5,
    maxProcesses = 2
}

sync {
    default.rsync,
    source = "/data/new",
    target = "172.18.30.18::new",
    delete = 'running',
    delay = 5,
    rsync     = {
        binary = "/usr/bin/rsync",
        archive = true,
        compress = false,
        verbose   = true
    }
}

sync {
    default.rsync,
    source = "/data",
    target = "172.18.34.41::new",
    delete = 'running',
    exclude = "upload",
    delay = 5,
    rsync     = {
        binary = "/usr/bin/rsync",
        archive = true,
        compress = false,
        verbose   = true
    }
}
fallback

对端rsyncd的配置如下:

# cat /etc/rsyncd.conf 
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[new]
path = /root
ignore errors
read only = false
list = false
hosts allow = 172.18.34.38
hosts deny = 0.0.0.0/32
fallback

这是个极端强力的工具,墙裂推荐!。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK