sebastianfeldmann / phpbu

PHP Backup Utility - Creates and encrypts database and file backups, syncs your backups to other servers or cloud services and assists you monitor your backup process
https://phpbu.de
Other
1.3k stars 110 forks source link

Amazon S3 Lifecycle #92

Open necenzurat opened 7 years ago

necenzurat commented 7 years ago

This is about the deleting backups after x days/months remotley (on Amazon S3).

https://docs.aws.amazon.com/AmazonS3/latest/dev/lifecycle-expire-general-considerations.html

Sebastian, any ideas how to implement it?

sebastianfeldmann commented 7 years ago

Hi, right now phpbu doesn't create Buckets, phpbu assumes that the bucket you configure already exists and if not the upload will fail. Since the TTL is a bucket-setting you can update its settings via API oder Management Console.

Have a look at this aws blog post. https://aws.amazon.com/de/blogs/aws/amazon-s3-object-expiration/

Hope that helps. Cheers, Sebastian

necenzurat commented 7 years ago

would be nice to automagically create the bucket and set the expiration date according to the cleanup functionality.

sebastianfeldmann commented 7 years ago

Yes adding an option to create the bucket if it doesn't exist would be nice. But I think there should be separate sync options to configure the bucket expiration settings. Firstly because remote and local cleanup should be separated and secondly because the bucket doesn't support "all" possible cleanup strategies and this would imply that all Sync implementations would support this, which they do not ;)

Maybe something like this

<option name="bucket.create" value="true"/>
<option name="bucket.ttl" value="2m"/>
sebastianfeldmann commented 7 years ago

The bucket create feature is now in dev-master I couldn't get the TTL thing to work. The S3 API does not accept the rules I'm trying to create for new buckets :/

necenzurat commented 7 years ago

In the case this does not work, a nice idea would be implementing a json store file something like composer.lock that would store local backups, hashes, remote backups, size, date time, etc. and maybe use that to delete remote files.

sebastianfeldmann commented 7 years ago

The crazy thing is there should be a way to set the bucket rules with the AWS SDK, but I could not get it to work. Sadly, for now, I did not find the time to investigate this further or try to find any working code examples.

The sweet thing about your idea is, that we could use it for every cloud storage integration.

planetahuevo commented 7 years ago

I am using the lifecycle just activating versioning and saving the file without the date and the time, this way Amazon understand is a new version automatically. In case it helps to others.