Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
customer-recall
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tools
customer-recall
Commits
a0f069dc
Commit
a0f069dc
authored
Sep 10, 2025
by
luoqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:数据库备份
parent
49954751
Pipeline
#3229
passed with stage
in 21 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
8 deletions
+78
-8
Dockerfile
+2
-2
database/scripts/backup_database.py
+66
-0
database/scripts/entrypoint.sh
+10
-6
No files found.
Dockerfile
View file @
a0f069dc
...
@@ -27,10 +27,10 @@ RUN pip install --no-cache-dir -r requirements.txt
...
@@ -27,10 +27,10 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY
. .
COPY
. .
# 创建必要的目录
# 创建必要的目录
RUN
mkdir
-p
progress_saves data/callbacks data/patients/clinics data/patients/merged data/exports
RUN
mkdir
-p
progress_saves data/callbacks data/patients/clinics data/patients/merged data/exports
database/backups
# 设置权限
# 设置权限
RUN
chmod +x
*
.py database/scripts/entrypoint.sh database/scripts/
*
.py
RUN
chmod +x
*
.py database/scripts/entrypoint.sh database/scripts/
*
.py
database/scripts/backup_database.py
# 暴露端口
# 暴露端口
EXPOSE
5000
EXPOSE
5000
...
...
database/scripts/backup_database.py
0 → 100644
View file @
a0f069dc
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
数据库备份脚本
在容器内执行数据库备份
"""
import
os
import
sys
import
subprocess
from
pathlib
import
Path
from
datetime
import
datetime
# 添加项目根目录到Python路径
project_root
=
Path
(
__file__
)
.
parent
.
parent
.
parent
sys
.
path
.
insert
(
0
,
str
(
project_root
))
def
run_command
(
command
,
description
):
"""执行命令并处理错误"""
print
(
f
"🔄 {description}..."
)
try
:
result
=
subprocess
.
run
(
command
,
shell
=
True
,
check
=
True
,
capture_output
=
True
,
text
=
True
,
cwd
=
project_root
)
print
(
f
"✅ {description} 成功"
)
if
result
.
stdout
:
print
(
f
"输出: {result.stdout}"
)
return
True
except
subprocess
.
CalledProcessError
as
e
:
print
(
f
"❌ {description} 失败"
)
print
(
f
"错误: {e.stderr}"
)
return
False
def
backup_database
():
"""备份数据库"""
print
(
"🚀 数据库备份工具启动"
)
print
(
f
"📍 项目根目录: {project_root}"
)
# 确保备份目录存在
backup_dir
=
project_root
/
"database"
/
"backups"
backup_dir
.
mkdir
(
exist_ok
=
True
)
# 生成带时间戳的备份文件名
timestamp
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d_
%
H
%
M
%
S"
)
backup_file
=
backup_dir
/
f
"auto_backup_{timestamp}.sql"
# 构建备份命令(容器内直接连接MySQL)
backup_command
=
f
"mysqldump -h mysql -u callback_user -pdev_password_123 callback_system > {backup_file}"
print
(
f
"📁 备份文件: {backup_file}"
)
if
run_command
(
backup_command
,
f
"备份数据库到 {backup_file.name}"
):
print
(
"🎉 数据库备份完成"
)
return
True
else
:
print
(
"❌ 数据库备份失败"
)
return
False
if
__name__
==
'__main__'
:
success
=
backup_database
()
sys
.
exit
(
0
if
success
else
1
)
database/scripts/entrypoint.sh
View file @
a0f069dc
...
@@ -50,8 +50,12 @@ log_info "📋 第一步:等待数据库就绪..."
...
@@ -50,8 +50,12 @@ log_info "📋 第一步:等待数据库就绪..."
python database/scripts/wait-for-db.py
python database/scripts/wait-for-db.py
log_success
"数据库连接就绪"
log_success
"数据库连接就绪"
# 第二步:执行数据库迁移
# 第二步:备份数据库
log_info
"📋 第二步:执行数据库迁移..."
log_info
"📋 第二步:备份数据库..."
python database/scripts/backup_database.py
||
log_warning
"数据库备份失败,但继续启动应用"
# 第三步:执行数据库迁移
log_info
"📋 第三步:执行数据库迁移..."
# 使用专门的迁移管理器
# 使用专门的迁移管理器
python database/scripts/migration_manager.py
python database/scripts/migration_manager.py
...
@@ -63,8 +67,8 @@ else
...
@@ -63,8 +67,8 @@ else
exit
1
exit
1
fi
fi
# 第
三
步:数据导入(如果需要)
# 第
四
步:数据导入(如果需要)
log_info
"📋 第
三
步:检查数据导入需求..."
log_info
"📋 第
四
步:检查数据导入需求..."
# 检查是否有患者数据需要导入
# 检查是否有患者数据需要导入
if
[
-f
"database/scripts/safe_import_patients.py"
]
&&
[
-d
"data/patients/clinics"
]
;
then
if
[
-f
"database/scripts/safe_import_patients.py"
]
&&
[
-d
"data/patients/clinics"
]
;
then
...
@@ -75,8 +79,8 @@ else
...
@@ -75,8 +79,8 @@ else
log_info
"无需数据导入"
log_info
"无需数据导入"
fi
fi
# 第
四
步:启动Flask应用
# 第
五
步:启动Flask应用
log_info
"📋 第
四
步:启动Flask应用..."
log_info
"📋 第
五
步:启动Flask应用..."
log_info
"🌐 应用将在端口 5000 启动"
log_info
"🌐 应用将在端口 5000 启动"
log_info
"🔗 健康检查端点: http://localhost:5000/api/health"
log_info
"🔗 健康检查端点: http://localhost:5000/api/health"
...
...
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