Skip to content

Commit 5e9800e

Browse files
committed
fix: restore with drop
1 parent eae6939 commit 5e9800e

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ S3 支持使用虚拟域名作为 endpoint,即可以将 region 或者 bucket
161161

162162
- MONGO_URI
163163
- MONGO_FILE_PREFIX
164+
- MONGO_DROP: 选填,在集合恢复前移除原有内容
164165
- BACKUP_LATEST_FILE
165166
- BACKUP_PWD
166167

docker/restore.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
must_inputs = ["MONGO_URI"]
1818
other_inputs = [
1919
"FILE_PREFIX",
20+
"MONGO_DROP",
2021
"BACKUP_PATH",
2122
"BACKUP_PWD",
2223
# S3 CONFIG
@@ -52,6 +53,7 @@ def check_bool(key):
5253
uri = os.environ["MONGO_URI"]
5354

5455
# 选填
56+
mongo_drop = check_bool("MONGO_DROP") if check_var("MONGO_DROP") else False
5557
backup_path = (
5658
os.environ["BACKUP_PATH"] if check_var("BACKUP_PATH") else DEFAULT_BACKUP_PATH
5759
)
@@ -128,7 +130,11 @@ def restore_file(file_path):
128130
)
129131

130132
# 恢复数据
131-
cmd = f'mongorestore --uri="{uri}" --gzip --archive={restore_path}'
133+
other_cmd = "--gzip"
134+
if mongo_drop:
135+
other_cmd += " --drop"
136+
137+
cmd = f'mongorestore --uri="{uri}" {other_cmd} --archive={restore_path}'
132138
subprocess.call(cmd, shell=True)
133139

134140
if is_crypt_file and backup_pwd:

helm-chart/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 1.7.0
18+
version: 1.7.1
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "1.7.0"
24+
appVersion: "1.7.1"

helm-chart/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ backup:
6969
image:
7070
registry: ""
7171
repository: 36node/mongodb-backup
72-
tag: 1.7.0
72+
tag: 1.7.1
7373
digest: ""
7474
## Specify a imagePullPolicy
7575
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
@@ -134,7 +134,7 @@ restore:
134134
image:
135135
registry: ""
136136
repository: 36node/mongodb-backup
137-
tag: 1.7.0
137+
tag: 1.7.1
138138
digest: ""
139139
## Specify a imagePullPolicy
140140
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'

0 commit comments

Comments
 (0)