-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync.sh
executable file
·34 lines (28 loc) · 1 KB
/
sync.sh
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
#!/bin/sh
# this script takes the following env vars
#
# - AWS_ACCESS_KEY_ID
# - AWS_SECRET_ACCESS_KEY
# - BUCKET
# - IDENTIFIER
# - REGION
(
cd ../recordings
rm -f sync.log
# TODO purge empty files before sync
# ACTIVE_PATH=`lsof -c sox | grep recordings | tr -s ' ' | cut -d ' ' -f 9`
# ACTIVE_FILE=`basename $ACTIVE_PATH`
# find -empty | grep -v $ACTIVE_FILE | xargs -I {} rm -- {}
aws s3 sync . s3://$BUCKET/$IDENTIFIER --region $REGION \
>>../streambox/sync.log 2>&1
if [ $? -eq 0 ]; then
# find the file which is currently being written to and delete all others
ACTIVE_PATH=`lsof -c sox | grep recordings | tr -s ' ' | cut -d ' ' -f 9`
# FIXME this fails when there is no active recording
ACTIVE_FILE=`basename $ACTIVE_PATH`
ls -1 | grep -v $ACTIVE_FILE | xargs -I {} rm -- {}
echo "Cleanup after sync complete." >>../streambox/sync.log
else
echo "Sync failed, skipping cleanup." >>../streambox/sync.log
fi
)