-
-
Save kklem0/483b6fb5c0a16ba582bf90eb969fc4ed to your computer and use it in GitHub Desktop.
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 | |
## Conventions: | |
## | |
## Working directory has the same name as the s3 bucket. | |
## Script is executed from the parent of this directory. | |
## | |
BUCKET=$1 | |
if [ ! -d ${BUCKET} ]; then | |
echo "Directory '${BUCKET}' not found." | |
exit | |
fi | |
inotifywait -m -qr -e modify,create,delete,moved_to,moved_from --format '%e %w%f' ${BUCKET} | while true | |
do | |
read -r op file; | |
case $op in | |
## Simple case: creating or modifying a file, upload it. | |
CREATE | MODIFY | MOVED_TO) | |
aws s3 cp $file s3://$file | |
;; | |
MOVED_TO,ISDIR) | |
aws s3 sync $file s3://$file | |
;; | |
MOVED_FROM,ISDIR) | |
aws s3 rm s3://$file --recursive | |
;; | |
DELETE | MOVED_FROM) | |
aws s3 rm s3://$file | |
;; | |
DELETE,ISDIR | CREATE,ISDIR) | |
echo Ignoring directories - S3 creates and destroys automatically | |
;; | |
*) | |
echo Unexpected op $op on file $file | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment