同步文件

使用 lsyncd

可以使用 apt , yum 安装。

1
2
3
4
5
6
7
8
9
10
11
12
# cat /etc/systemd/system/lsyncd.service;
[Unit]
Description=Live Syncing Daemon
After=network.target

[Service]
ExecStart=/usr/bin/lsyncd -nodaemon /etc/lsyncd.conf.lua
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

编辑配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 2
}

local excludes = {
"._*", -- macOS 生成文件(你要的)
".DS_Store", -- mac Finder
"*.tmp", -- 临时文件
"*.swp", -- vim
}

-- prod
sync {
default.rsync,
source = "/data/service/webdav/data/coze-loop-prod",
target = "/nas/ns-sh-hs-prod-k8s-nas/pvc-6f1e2fe9-fe41-46cf-a1ab-f546553b6e6a/conf",
delete = false,
exclude = excludes,
rsync = {
archive = true,
compress = false,
verbose = true,
whole_file = true,
}
}

-- dev
sync {
default.rsync,
source = "/data/service/webdav/data/coze-loop-dev",
target = "/nas/ns-hs-sh-dev-k8s-nas/pvc-4f2e80b7-bf36-413c-8c6c-5db443a5b936/conf",
delete = false,
exclude = excludes,
rsync = {
archive = true,
compress = false,
verbose = true,
whole_file = true, -- 每次都传整个文件
}
}
-- dev ssh 需要免密
sync {
default.rsyncssh,
source = "/data/service/webdav/data/coze-loop-dev",
host = "10.23.0.66",
delete = "false",
targetdir = "/data/service/coze-loop/release/deployment/docker-compose/conf",
rsync = {
archive = true,
compress = true,
verbose = true,
}
}

可以将 文件通过 webdav 挂载出来,更新后 同步到各个文件目录

docker-compose.yaml 文件

1
2
3
4
5
6
7
8
9
10
11
12
[email protected]:/data/service/webdav# cat docker-compose.yaml 
services:
webdav:
image: ghcr.io/hacdias/webdav
container_name: webdav
ports:
- "6060:6060"
volumes:
- ./config.yml:/config.yml:ro
- ./data:/data
command: ["-c", "/config.yml"]
restart: unless-stopped

config.yml 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
address: 0.0.0.0
port: 6060

# TLS-related settings if you want to enable TLS directly.
tls: false
cert: cert.pem
key: key.pem

# Prefix to apply to the WebDAV path-ing. Default is '/'.
prefix: /

# Enable or disable debug logging. Default is 'false'.
debug: false

# Disable sniffing the files to detect their content type. Default is 'false'.
noSniff: false

# Whether the server runs behind a trusted proxy or not. When this is true,
# the header X-Forwarded-For will be used for logging the remote addresses
# of logging attempts (if available).
behindProxy: false

# The directory that will be able to be accessed by the users when connecting.
# This directory will be used by users unless they have their own 'directory' defined.
# Default is '.' (current directory).
directory: /data/

# The default permissions for users. This is a case insensitive option. Possible
# permissions: C (Create), R (Read), U (Update), D (Delete). You can combine multiple
# permissions. For example, to allow to read and create, set "RC". Default is "R".
permissions: R

# The default permissions rules for users. Default is none. Rules are applied
# from last to first, that is, the first rule that matches the request, starting
# from the end, will be applied to the request. Rule paths are always relative to
# the user's directory.
rules: []

# The behavior of redefining the rules for users. It can be:
# - overwrite: when a user has rules defined, these will overwrite any global
# rules already defined. That is, the global rules are not applicable to the
# user.
# - append: when a user has rules defined, these will be appended to the global
# rules already defined. That is, for this user, their own specific rules will
# be checked first, and then the global rules.
# Default is 'overwrite'.
rulesBehavior: overwrite

# Logging configuration
log:
# Logging format ('console', 'json'). Default is 'console'.
format: console
# Enable or disable colors. Default is 'true'. Only applied if format is 'console'.
colors: true
# Logging outputs. You can have more than one output. Default is only 'stderr'.
outputs:
- stderr

# CORS configuration
cors:
# Whether or not CORS configuration should be applied. Default is 'false'.
enabled: true
credentials: true
allowed_headers:
- Depth
allowed_hosts:
- http://localhost:8080
allowed_methods:
- GET
exposed_headers:
- Content-Length
- Content-Range

# The list of users. If the list is empty, then there will be no authentication.
# Otherwise, basic authentication will automatically be configured.
#
# If you're delegating the authentication to a different service, you can proxy
# the username using basic authentication, and then disable webdav's password
# check using the option:
#
# noPassword: true
users:
# Example 'admin' user with plaintext password.
- username: admin
password: password
permissions: CRUD
# Example 'john' user with bcrypt encrypted password, with custom directory.
# You can generate a bcrypt-encrypted password by using the 'webdav bcrypt'
# command lint utility.
- username: john
password: "{bcrypt}$2y$10$zEP6oofmXFeHaeMfBNLnP.DO8m.H.Mwhd24/TOX2MWLxAExXi4qgi"
directory: /another/path
# Example user whose details will be picked up from the environment.
- username: basic
password: basic-ttttt
# Override default permissions.
permissions: CRUD
rules:
# With this rule, the user CANNOT access {user directory}/some/files.
- path: /some/file
permissions: none
# With this rule, the user CAN create, read, update and delete within
# {user directory}/public/access.
- path: /public/access/
permissions: CRUD
# With this rule, the user CAN read and update all files ending with .js.
# It uses a regular expression.
- regex: "^.+.js$"
permissions: RU