Skip to content

Commit 9889fad

Browse files
committed
enh: also list latest instance backup
1 parent bb41d82 commit 9889fad

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

dcor_control/cli/status.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ def status():
7474
click.echo(f"S3 instance backup number: {bbi['num_other']}")
7575
click.echo(f"S3 instance backup size: "
7676
f"{bbi['size_other']/1024**3:.0f} GiB")
77+
click.echo(f"S3 instance backup latest: {bbi['object_keys'][-1]}")
7778

7879

79-
def get_bucket_info(bucket_name):
80+
def get_bucket_info(bucket_name, ret_object_keys=False):
8081
s3_client, s3_session, s3_resource = s3.get_s3()
8182
num_resources = 0
8283
num_other = 0
8384
size_resources = 0
8485
size_other = 0
86+
object_keys = []
8587

8688
kwargs = {"Bucket": bucket_name,
8789
"MaxKeys": 500
@@ -90,6 +92,9 @@ def get_bucket_info(bucket_name):
9092
resp = s3_client.list_objects_v2(**kwargs)
9193

9294
for obj in resp.get("Contents", []):
95+
if ret_object_keys:
96+
object_keys.append(obj["Key"])
97+
9398
if obj["Key"].startswith("resource/"):
9499
num_resources += 1
95100
size_resources += obj["Size"]
@@ -103,9 +108,12 @@ def get_bucket_info(bucket_name):
103108
kwargs["ContinuationToken"] = resp.get(
104109
"NextContinuationToken")
105110

106-
return {
111+
data = {
107112
"num_resources": num_resources,
108113
"num_other": num_other,
109114
"size_resources": size_resources,
110115
"size_other": size_other,
111116
}
117+
if ret_object_keys:
118+
data["object_keys"] = sorted(object_keys)
119+
return data

0 commit comments

Comments
 (0)