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

Glacier support #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Glacier support #19

wants to merge 6 commits into from

Conversation

kithrup
Copy link

@kithrup kithrup commented Jun 10, 2017

Adds an option and config file entry for glacier support; also tries to create the specified bucket if it doesn't exist. I haven't fully tested the restore part.

Copy link
Contributor

@rciorba rciorba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! Glacier storage seems quite useful.

Adding some tests for this new feature would be nice ;)

z3/snap.py Outdated
lifecycle_rule_name = "z3 transition"
if args.s3_prefix:
lifecycle_rule_name += " " + args.s3_prefix.replace("/", " ")
while lifecycle_rule_name.endswith(" "):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to use string.rstrip(" ")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another holdover, I was originally changing / to - :). Changed.

z3/snap.py Outdated
except boto.exception.S3ResponseError as e:
if e.error_code == 'NoSuchBucket':
# Let's try creating it
bucket = s3.create_bucket(bucket_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

z3/snap.py Outdated
else:
raise

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please extract the whole bucket life-cycle handling section to a separate function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

z3/snap.py Outdated
except AttributeError:
# This seems to be if the FakeKey object doesn't have the ongoing_restore attribute
pass
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to do a blanket except and re-raise, that's Python's default behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original code had some other there, I changed it to a pass simply as a placeholder. Fixed.

z3/snap.py Outdated
current_snap.key.restore(days=5)
raise Exception('snapshot {} is currently in glacier storage, requesting transfer now'.format(snap_name))
except AttributeError:
# This seems to be if the FakeKey object doesn't have the ongoing_restore attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the AttributeError to get the tests to pass is not very nice. Maybe now it's just because of FakeKey.ongoing_restore, but in the future it could mask a legitimate bug.

A better course of action would be to change FakeKey to this:


class FakeKey(object):
    def __init__(self, name, metadata=None, storage_class="STANDARD_IA"):
        self.name = name
        self.key = name
        self.metadata = metadata
        self.size = 1234
        self.ongoing_restore = None
        self.storage_class = storage_class

Then drop the exception handling all-together.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, making that change in my branch.

z3/snap.py Outdated
transition=transition)
print("lifecycle = {}".format(lifecycle.to_xml()), file=sys.stderr)
if lifecycle is not None:
bucket.configure_lifecycle(lifecycle)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the transition to GLACIER happen only on upload?
I'm especially concerned by the fact this alters the storage class even if ran with --dry-run. A dry run should have no side effects.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the reasons I did that was that I have it set up to remove the lifecycle rule if use_glacier is no longer in the configuration.

Changed it.

z3/snap.py Outdated
if current_snap.key.ongoing_restore == True:
raise Exception('snapshot {} is currently being restore from glocier; try again later'.format(snap_name))
if current_snap.key.storage_class == "GLACIER":
current_snap.key.restore(days=5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be getting it wrong but: it seems this only handles glacier-restore for the most recent snapshot. Shouldn't all 'to-be-downloaded' snapshots be glacier-restored in one run?

Would it not make sense to move the glacier-restore logic in to the loop that also figures out which snapshots need downloading, so it can ask for them all to be restored?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done a restore at all, so it wasn't clear to me what I needed to do. That would be loop that adds to to_restore?

z3/snap.py Outdated
try:
if current_snap.key.ongoing_restore == True:
raise Exception('snapshot {} is currently being restore from glocier; try again later'.format(snap_name))
if current_snap.key.storage_class == "GLACIER":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... their documentation states the storage class should remain GLACIER. Is that not the case? http://docs.aws.amazon.com/AmazonS3/latest/dev/restoring-objects.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Experimenting now. It'll take a few hours for it to happen. I was going by the boto documentation, which seemed to imply it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed via experimentation. The expiration count is pretty arbitrary, but I am not sure the best way to make that configurable.

kithrup added 3 commits June 16, 2017 09:36
* Add the glacier-related attributes to FakeKey.
* Because of that, don't catch AttributeError.  Yay
* Don't change the key's storage class in restore if dry_run.
* Move the lifecycle management into a function
* Related to that, only call if it dry_run is false.
* Somewhat-related to that, only create the bucket if the subcommand is
backup.
	This still creates the bucket even if dry run is given.
…"glacier"

after an object is restored.  If ongoing_restore is None, then the object has
not been restored.
@Fyb3roptik
Copy link

Any idea why this died?

@kithrup
Copy link
Author

kithrup commented Oct 7, 2020

Project abandonment.

@kithrup
Copy link
Author

kithrup commented Oct 7, 2020

Project abandonment, i presume. Alas.

@Fyb3roptik
Copy link

Any chance you can do it to this forked repo?

https://github.com/mmontagna/zfs3backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants