myENA / consul-backinator

Command line Consul backup and restore utility supporting KVs, ACLs and Queries
Mozilla Public License 2.0
226 stars 22 forks source link

S3 Upload #19

Closed samber closed 8 years ago

samber commented 8 years ago

Hi guys !

What about a parameter uploading to/restoring from AWS S3, instead of -file ?

aaronhurt commented 8 years ago

I can definitely see the benefit there. I'll give it a look in the next few days.

samber commented 8 years ago

Thanks a lot @leprechau ! :+1:

aaronhurt commented 8 years ago

@samber Testing this locally and I had a question ... Would you like to directly push the blobs to S3 or have it generate the local file and then push that to S3 afterwards?

samber commented 8 years ago

I've heard some people having more than 1Go of KV in consul, so pushing directly would be awesome ! Unfortunately, if it requires encryption, you will not be able to stream data into s3, because we have to put the whole KV store in a -very large- buffer. I think storing data in a file would be the best solution.

I think we can use some -s3-region -s3-path -aws-access-key -aws-secret-key flags such as:

WDYT ?

aaronhurt commented 8 years ago

I've seen a few places that are using URIs to capture all of the S3 data in combination with environment variables. Since we are already allowing plenty of environment variables for the Consul portions I like the idea of expanding that to S3 as well. This is my current implementation locally:

Everything in the URI...

consul-backinator backup -s3 "s3://access-key:secret-key@my-bucket/consul/latest?region=us-east-1"

A simple URI with exports...

export AWS_ACCESS_KEY_ID=my-access-key
export AWS_SECRET_ACCESS_KEY=my-secret-key
export AWS_REGION=us-east-1
consul-backinator backup -s3 "s3://my-bucket/consul/latest"

This only adds a single option to the list for the various commands to keep the help listing a bit more sane and keeps with the current implementation of putting most common things in environment variables.

Would this work for you?

aaronhurt commented 8 years ago

I changed my mind about the previous post. I've actually not added any options but instead used the existing -file option to specify either a local file OR a remote S3 location.

With CONSUL_HTTP_ADDR, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION exported ...

2016/11/08 16:17:31 [Success] Backed up 16 keys from consul.local:8500/apps/hmm/ to s3://ena-testing/consul/latest
Keep your backup and signature files in a safe place.
You will need both to restore your data.
charlie:consul-backinator ahurt$ ./consul-backinator restore -file="s3://ena-testing/consul/latest" -prefix=/apps/hmm/
2016/11/08 16:17:38 [Success] Restored 16 keys from s3://ena-testing/consul/latest?region=us-east-1 to consul.local:8500/apps/hmm/
aaronhurt commented 8 years ago

@samber The working code is committed to master. Please test it and let me know what you think.

samber commented 8 years ago

Ok :+1:

I agree with everything. Thanks for this feature ! ;-)

aaronhurt commented 8 years ago

Awesome, think I'll push a new release that contains these changes and the TLS customizations from #16 and #18