Quantcast

Usage

Here are a few usage scenarios for this tool.
Throughout this page, I am assuming that you are using the one-jar version of the tool, and the file name is aws-version-mgmt.one-jar.jar . Quite likely, the one-jar filename will include the version number as well, so please adjust the following based on the version number you are using. I have also included in here the version numbers where functionality became available -- please make sure you are using the correct version when running the command.
Also, I am not including any AWS credentials in the command, for obvious reasons, please replace the elipsis (...) in the commands below with your own. The bucket name is assumed to be MyBucket -- please supply your own bucket name in the command line.

Purge everything in a bucket To remove everything in an S3 bucket with versioning enabled (including versions of files which have been deleted and are left "orphan"), use this command:

java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -purge

Delete files older than a given date This can be used as a regular cleanup task -- for instance you can set up a monthly cron job to delete everything older than the current month. Simply use something like this:

java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -bd "2013-01-01" -purge

Please note that in the above example I have supplied the date 1st of January 2013, you will have to replace the value 2013-01-01 with the month you are interested in.

Schedule a regular cleanup of the bucket This is an extension of the above usage scenario, where at the beginning of each month, you might want to do a cleanup and only keep the files that were created last month. For that you will have to schedule a cron job using a script like this (assuming bash as a shell):

#!/bin/bash # This script is assumed to be run on 1st of each month # and only keeps files generated last month LAST_MONTH=`date --date="last month" +"%y-%m"` FULL_DATE="${LAST_MONTH}-01" java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -bd "$FULL_DATE" -purge

While it is true that AWS offers Lifecycle Rules (also known as "Object Lifecycle Management" or "Object Expiry"), which enables you to do just that for a normal bucket (which doesn't have versioning enabled), unfortunately the lifecycle rules are not available for a versioning-enabled bucket, and as such quite likely you will find yourself in the need of a tool like this -- hence the above example, that I have encountered myself very often.

Delete files created earlier than a certain time today If you have performed some S3-intensive tests for instance one day and want to get rid of some of the versions created during that test, you can still use the -bd parameter, but also include a time. Please note that since there is a space separator in between the date and time, you will have to supply the date/time in the command line in quotes:

java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -bd "2013-01-01 17:01:50" -purge

Please note that in the above example I have supplied the date 1st of January 2013 and the time of 5pm minute 1 and 50 seconds, you will have to replace the value 2013-01-01 17:01:50 with the date/time you are interested in.

Delete all files/versions in a directory If you have multiple directories in your bucket and only want to get rid of the files in a certain directory, you can use the purge command like this.

java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -dir MyDir -purge

Please note that I am assuming in the above example the directory name to be MyDir, you will have to replace that with the name of the directory you are trying to clean up. Also note that the trailing slash for the directory name is not required, the above is equivalent to this:

java -jar aws-version-mgmt.one-jar.jar -a ... -s ... -b MyBucket -dir MyDir/ -purge