Last active
May 8, 2016 09:07
-
-
Save tuxnker/2efeb4f7ddb07b070360210d33cf311e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Move Files in between s3 buckets based on a list | |
#Use Standard_IA so storage will be cheaper | |
while [[ $# > 1 ]] | |
do | |
key="$1" | |
case $key in | |
-f|--file) | |
FILE="$2" | |
shift # past argument | |
;; | |
-s|--src) | |
SRC_BUCKET="$2" | |
shift # past argument | |
;; | |
-d|--dst) | |
DST_BUCKET="$2" | |
shift # past argument | |
;; | |
--default) | |
DEFAULT=YES | |
;; | |
*) | |
echo "Usage s3_cleanup.sh -f items_file -s src_bucket -d dst_bucket" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
while read line; | |
do | |
[ -z "$line" ] && continue | |
length=${#line} | |
((length--)) | |
if [ "${line:$length:1}" == "/" ] ; then | |
echo "$line is a folder" | |
aws s3 mv s3://$SRC_BUCKET/"$line" s3://$DST_BUCKET/ --storage-class STANDARD_IA --recursive | |
else | |
aws s3 mv s3://$SRC_BUCKET/"$line" s3://$DST_BUCKET/ --storage-class STANDARD_IA | |
fi | |
done < $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment