Archiving script for exising buckets in s3. To use make install s3cmd.
Last active
August 29, 2015 14:14
-
-
Save stefanooldeman/e9ff83b007696362ac77 to your computer and use it in GitHub Desktop.
Move files from one bucket to the other with style
This file contains 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 | |
OLD= | |
NEW= | |
S3_FILES=.s3_files.txt | |
fetch_files_list() { | |
s3cmd --access_key <yourkey> \ | |
--secret_key <yoursecret> \ | |
ls s3://$OLD > $S3_FILES | |
} | |
if [ -f $S3_FILES ]; then | |
while true; do | |
read -p "Already found ${S3_FILES}, re-use this list? [y/N]?" yn | |
case $yn in | |
[Yy]* ) echo "nothing to do"; break;; | |
[N]* ) fetch_files_list; break;; | |
* ) echo "Invalid option: try again.";; | |
esac | |
done | |
else | |
fetch_files_list | |
fi | |
while read line; do | |
OBJECT=`echo $line | cut -d' ' -f4` | |
OBJECT_NAME=`basename $OBJECT` | |
# get the date info | |
DATE=`echo $OBJECT | egrep -o '[0-9]{8}'` | |
YEAR=${DATE:0:4} | |
MONTH=${DATE:4:2} | |
# assemble everything | |
NEW_PATH=s3://${NEW}/archive/${YEAR}/${MONTH}/${OBJECT_NAME} | |
s3cmd --access_key <yourkey> \ | |
--secret_key <yoursecret> \ | |
mv $OBJECT $NEW_PATH | |
done < $S3_FILES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment