Merge ~andersson123/autopkgtest-cloud:db-backup-add-checksum-to-filename into autopkgtest-cloud:master

Proposed by Tim Andersson
Status: Merged
Merged at revision: 752cfb13f8bf24d007ad04d3972e80f6e95c7de8
Proposed branch: ~andersson123/autopkgtest-cloud:db-backup-add-checksum-to-filename
Merge into: autopkgtest-cloud:master
Diff against target: 40 lines (+14/-1)
1 file modified
charms/focal/autopkgtest-web/webcontrol/db-backup (+14/-1)
Reviewer Review Type Date Requested Status
Brian Murray Approve
Skia Needs Fixing
Review via email: mp+462687@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

I don't know what workflow you have in mind here but I'd think it would be easier to have the checksum in the filename so that when you copy the item out of swift and put it on your local disk you have the checksum right there instead of having to look it up somewhere else.

Revision history for this message
Tim Andersson (andersson123) wrote :

Ah, I see what you mean, that makes more sense. I'll amend this MP.

Revision history for this message
Tim Andersson (andersson123) wrote :

Amended and ready for re-review

Revision history for this message
Skia (hyask) :
review: Needs Fixing
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Tim Andersson (andersson123) wrote :

This is amended and ready for re-review

Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for fixing that. Approved provided CI passes.

review: Approve
Revision history for this message
Tim Andersson (andersson123) wrote :

It looks like we're having issues with CI. I pushed this EOD yesterday ish. So it should've completed by now. I'll run LPCI locally and if it passes, I'll merge this.

Revision history for this message
Tim Andersson (andersson123) wrote :

LPCI passed on my machine, going to merge it, I've added a note on my todo list to look into CI weirdness

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/webcontrol/db-backup b/charms/focal/autopkgtest-web/webcontrol/db-backup
2index 4ca6a20..08b8513 100755
3--- a/charms/focal/autopkgtest-web/webcontrol/db-backup
4+++ b/charms/focal/autopkgtest-web/webcontrol/db-backup
5@@ -8,6 +8,7 @@ import atexit
6 import configparser
7 import datetime
8 import gzip
9+import hashlib
10 import logging
11 import os
12 import shutil
13@@ -96,6 +97,12 @@ def create_container_if_it_doesnt_exist(swift_conn: swiftclient.Connection):
14 )
15
16
17+def get_db_backup_checksum():
18+ with open("%s.gz" % DB_BACKUP_PATH, "rb") as bkp_f:
19+ md5 = hashlib.md5(bkp_f.read()).hexdigest()
20+ return md5
21+
22+
23 def upload_backup_to_db(
24 swift_conn: swiftclient.Connection,
25 ) -> swiftclient.Connection:
26@@ -103,7 +110,13 @@ def upload_backup_to_db(
27 Upload compressed database to swift storage under container db-backups
28 """
29 now = datetime.datetime.utcnow().strftime("%Y/%m/%d/%H_%M_%S")
30- object_path = "%s/%s" % (now, DB_PATH.name + ".gz")
31+ checksum = get_db_backup_checksum()
32+ object_path = "%s/%s-%s.%s" % (
33+ now,
34+ DB_PATH.name.split(".")[0],
35+ checksum,
36+ "db.gz",
37+ )
38 for retry in range(SWIFT_RETRIES):
39 try:
40 swift_conn.put_object(

Subscribers

People subscribed via source and target branches