Skip to content

Commit

Permalink
fix(backend): 备份巡检日期修复 close #1763
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlook committed Nov 13, 2023
1 parent aea7eec commit e0de5ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions dbm-services/common/go-pubpkg/iocrypt/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
)

// doEncryptFile example
// usually use cmutil EncryptOpt
func doEncryptFile() error {
srcFilename := "aaa.tar"
srcFile, err := os.Open(srcFilename)
Expand Down
2 changes: 2 additions & 0 deletions dbm-services/common/go-pubpkg/iocrypt/gpg.go
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package iocrypt

// gpg file encrypt: not implemented yet
6 changes: 4 additions & 2 deletions dbm-services/mysql/db-tools/mysql-dbbackup/docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ EncryptElgo =
- 留空默认为 openssl
- 如果是 xbcrypt,默认从工具目录下找 `bin/xbcrypt`,也可以指定工具全路径
3. EncryptAlgo: 加密算法,留空会有默认加密算法
- openssl [aes-256-cbc, aes-128-cbc, sm4-cbc],文件后缀 `.enc`。sm4-cbc 为国密对称加密算法
- openssl [aes-256-cbc, aes-128-cbc, sm4-cbc],文件后缀 `.enc`
sm4-cbc 为国密对称加密算法,需要 mysql 本机上的 openssl>1.1.1
- xbcrypt [AES256, AES192, AES128],文件后缀 `.xb`
4. EncryptPublicKey: public key 文件
- 用于 对 passphrase 加密,上报加密字符串。需要对应的平台 私钥 secret key 才能对 加密后的passphrase 解密
Expand All @@ -231,7 +232,8 @@ openssl rsautl -decrypt -inkey rsa.pem -in encrypted.key
// 3. 使用密码 passphrase 解密文件
```
一般 passphrase 需要从平台的页面获取,因为私钥不能泄露给使用者。

**用户只能拿到加密后的密码,明文 passphrase 需要从平台的页面解密获取,因为解密用的私钥不能泄露。**

- openssl 解密文件
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import datetime
from collections import defaultdict
from datetime import datetime, timedelta

from django.utils.translation import ugettext as _

Expand Down Expand Up @@ -49,9 +49,11 @@ def _check_binlog_backup(cluster_type):
"""
for c in Cluster.objects.filter(cluster_type=cluster_type):
backup = ClusterBackup(c.id, c.immute_domain)
now_time = datetime.datetime.now().date()
start_time = datetime.datetime.combine(now_time, datetime.time())
end_time = start_time + datetime.timedelta(hours=23, minutes=59, seconds=59)
now = datetime.now()
yesterday = now - timedelta(days=1)
start_time = datetime(yesterday.year, yesterday.month, yesterday.day)
end_time = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59)

items = backup.query_binlog_from_bklog(start_time, end_time)
instance_binlogs = defaultdict(list)
shard_binlog_stat = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import datetime
from collections import defaultdict
from datetime import datetime, timedelta

from django.utils.translation import ugettext as _

Expand Down Expand Up @@ -54,12 +54,13 @@ def _check_tendbha_full_backup():
"""
for c in Cluster.objects.filter(cluster_type=ClusterType.TenDBHA):
backup = ClusterBackup(c.id, c.immute_domain)
now_time = datetime.datetime.now().date()
start_time = datetime.datetime.combine(now_time, datetime.time())
end_time = start_time + datetime.timedelta(hours=23, minutes=59, seconds=59)
now = datetime.now()
yesterday = now - timedelta(days=1)
start_time = datetime(yesterday.year, yesterday.month, yesterday.day)
end_time = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59)

items = backup.query_backup_log_from_bklog(start_time, end_time)
# print("cluster={} backup_items:{}".format(c.immute_domain, items))

for i in items:
if i.get("data_schema_grant", "") == "all":
bid = i.get("backup_id")
Expand Down Expand Up @@ -99,12 +100,13 @@ def _check_tendbcluster_full_backup():
"""
for c in Cluster.objects.filter(cluster_type=ClusterType.TenDBCluster):
backup = ClusterBackup(c.id, c.immute_domain)
now_time = datetime.datetime.now().date()
start_time = datetime.datetime.combine(now_time, datetime.time())
end_time = start_time + datetime.timedelta(hours=23, minutes=59, seconds=59)
now = datetime.now()
yesterday = now - timedelta(days=1)
start_time = datetime(yesterday.year, yesterday.month, yesterday.day)
end_time = datetime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59)

items = backup.query_backup_log_from_bklog(start_time, end_time)
# print("cluster={} backup_items:{}".format(c.immute_domain, items))

for i in items:
if i.get("data_schema_grant", "") == "all":
bid = "{}#{}".format(i.get("backup_id"), i.get("shard_value"))
Expand Down

0 comments on commit e0de5ac

Please sign in to comment.