-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(s3-client): add option to rotate dumps (#1052)
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# check mandatory environment variables | ||
MANDATORY_VARS="AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_ENDPOINT_URL DESTINATION_PATH" | ||
for VAR in $MANDATORY_VARS; do | ||
if [[ -z "${!VAR}" ]]; then | ||
echo "${VAR} environment variable is empty" | ||
exit 1 | ||
fi | ||
done | ||
|
||
./dump-upload.sh | ||
|
||
if ! [[ -z $RETENTION_DAYS ]]; then | ||
./rotate-dumps.sh | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
aws s3 ls $DESTINATION_PATH/ | grep " DIR " -v | while read -r line; | ||
do | ||
createDate=`echo $line | awk {'print $1" "$2'}` | ||
createDate=`date -d "$createDate" +%s` | ||
olderThan=`date -d "-$RETENTION_DAYS days" +%s` | ||
|
||
if [[ $createDate -lt $olderThan ]] | ||
then | ||
fileName=`echo $line | awk {'print $4'}` | ||
if [[ $fileName != "" ]] | ||
then | ||
echo "Deleting $DESTINATION_PATH/$fileName" | ||
aws s3 rm "$DESTINATION_PATH/$fileName" | ||
fi | ||
fi | ||
done; |
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