Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
db-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yzy
db-tools
Commits
7c08df89
Commit
7c08df89
authored
Sep 10, 2026
by
wangteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码提交
parent
d57928c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
deploy_server.py
deploy_server.py
+54
-0
No files found.
deploy_server.py
0 → 100644
View file @
7c08df89
#!/usr/bin/env python3
"""db-tools 发版:上传 → 备份旧版 → 解压 → 重启 → 验证。
不动 /opt/app/db-tool/web/data/(web.db、backups、backup-config.json、sources)
不动服务器自己的 configs/llm.yaml(tar 里就没有)"""
import
sys
,
os
,
paramiko
HOST
,
USER
=
"192.168.20.175"
,
"root"
pw
=
os
.
environ
.
get
(
"DBTOOL_PW"
)
if
not
pw
:
sys
.
exit
(
"set DBTOOL_PW first"
)
c
=
paramiko
.
SSHClient
()
c
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
c
.
connect
(
HOST
,
username
=
USER
,
password
=
pw
,
timeout
=
10
,
look_for_keys
=
False
,
allow_agent
=
False
)
def
run
(
cmd
,
must
=
True
):
_
,
out
,
err
=
c
.
exec_command
(
cmd
,
timeout
=
120
)
o
,
e
=
out
.
read
().
decode
(
"utf-8"
,
"replace"
),
err
.
read
().
decode
(
"utf-8"
,
"replace"
)
rc
=
out
.
channel
.
recv_exit_status
()
print
(
f"$
{
cmd
}\
n
{
o
}{
(
'[stderr] '
+
e
)
if
e
.
strip
()
else
''
}
rc=
{
rc
}\
n
"
)
if
must
and
rc
!=
0
:
sys
.
exit
(
f"FAILED rc=
{
rc
}
:
{
cmd
}
"
)
return
o
sftp
=
c
.
open_sftp
()
sftp
.
put
(
"backend-deploy.tgz"
,
"/tmp/dbtool-backend.tgz"
)
sftp
.
put
(
"frontend-deploy.tgz"
,
"/tmp/dbtool-frontend.tgz"
)
sftp
.
close
()
print
(
"uploaded both tarballs
\
n
"
)
# 0) 部署前快照(证明 data/ 没被碰)
run
(
"md5sum /opt/app/db-tool/web/data/web.db; ls /opt/app/db-tool/web/data/backups | wc -l"
)
# 1) 备份当前版本
run
(
"TS=$(date +%Y%m%d-%H%M%S) && mkdir -p /opt/app/db-tool/releases/$TS && "
"cp -a /opt/app/db-tool/web/backend /opt/app/db-tool/releases/$TS/backend && "
"cp -a /opt/web/db-tool /opt/app/db-tool/releases/$TS/frontend && echo backup at $TS"
)
# 2) 解压后端(覆盖 backend/,不动 data/、logs/、服务器 llm.yaml)
run
(
"tar xzf /tmp/dbtool-backend.tgz -C /opt/app/db-tool/web/ && "
"find /opt/app/db-tool/web/backend -name __pycache__ -type d -exec rm -rf {} + ; "
"ls /opt/app/db-tool/web/backend/configs/"
)
# 3) 前端:清旧 assets 再解压(避免旧 hash 文件堆积)
run
(
"rm -rf /opt/web/db-tool/assets && tar xzf /tmp/dbtool-frontend.tgz -C /opt/web/db-tool/ && ls /opt/web/db-tool/ /opt/web/db-tool/assets/"
)
# 4) 重启
run
(
"systemctl restart db-tool && sleep 4 && systemctl is-active db-tool && ss -tlnp | grep 8767"
)
# 5) 部署后核对 data/ 未变 + 日志干净
run
(
"md5sum /opt/app/db-tool/web/data/web.db; ls /opt/app/db-tool/web/data/backups | wc -l; journalctl -u db-tool -n 5 --no-pager | tail -5"
)
c
.
close
()
print
(
"DEPLOY DONE"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment