-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3-auto-sync.sh
More file actions
46 lines (36 loc) · 920 Bytes
/
s3-auto-sync.sh
File metadata and controls
46 lines (36 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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