Skip to content

Commit

Permalink
Merge pull request #6 from siemens/feat/snap/store-date
Browse files Browse the repository at this point in the history
feat(snap): Add creation time to name

Reviewed-by : anupam.ghosh@siemens.com
  • Loading branch information
ag4ums authored Jul 21, 2021
2 parents cb17d66 + 5822c83 commit d8f4d0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ use delete with caution

The script will store snapshots with following structure in S3:
```
snap/<snapshot-name>/<snapshot-id>-<%Y-%m-%d_%H-%M-%S-%f>.tar
snap/<snapshot-name>/<snapshot-id>-<creation-time>-<now-time>.tar
```

The snaphost name gets spaces ` ` and `/` replaces as `+` and `_` respectively.
And the date/time is in ISO 8601 format.

This section is controlled by `get_key_for_upload()` of `S3Handler`.

Expand All @@ -185,6 +186,8 @@ This section is controlled by `get_key_for_upload()` of `S3Handler`.
1. Create a new volume of the desired size in AWS and attach to an instance.
- You can also check for `x-amz-meta-disc-size` metadata attached to the S3
object to get the estimated size of unpacked files.
- The meta tag `snap-volume-size` also stores the size of volume from which
the snapshot was created.
2. Download the snapshot from S3 to the instance.
1. If the upload was splitted, all the parts must be combined into one.
- `cat <downloaded_parts> > <single_huge>.tar`
Expand Down
2 changes: 2 additions & 0 deletions src/snap_to_bucket/ec_2_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get_snapshots(self):
for snap in response['Snapshots']:
snapshot = dict()
snapshot['id'] = snap['SnapshotId']
snapshot['created'] = snap['StartTime']
snapshot['volumesize'] = snap['VolumeSize']
for tag in snap['Tags']:
if tag['Key'].lower() == "name":
snapshot['name'] = tag['Value']
Expand Down
7 changes: 5 additions & 2 deletions src/snap_to_bucket/s3_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ def __get_key_uploadid(self, snapshot, size, partno):
"""
meta_data = dict()
content_type = 'application/x-tar'
timestr = datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
timestr = datetime.now().isoformat(timespec='seconds')
created = snapshot['created'].isoformat(timespec='seconds')
name = snapshot['name'].replace(' ', '+').replace('/', '_')
key = f"snap/{name}/{snapshot['id']}-{timestr}"
key = f"snap/{name}/{snapshot['id']}-{created}-{timestr}"
meta_data["creation-time"] = snapshot['created'].isoformat()
meta_data["snap-volume-size"] = f"{snapshot['volumesize']} GiB"
if partno == -1:
key = f"{key}.tar"
if self.gzip:
Expand Down

0 comments on commit d8f4d0f

Please sign in to comment.