Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snap): Add creation time to name #6

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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