Skip to content
This repository was archived by the owner on Apr 27, 2024. It is now read-only.

Added feature DATE_PREFIX, fixed incorrect shebang #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The below table lists all of the Environment Variables that are configurable for
| BACKUP_TIMESTAMP | **(Optional)** Date string to append to the backup filename ([date](http://man7.org/linux/man-pages/man1/date.1.html) format). Leave unset if using S3 Versioning and date stamp is not required. |
| BACKUP_COMPRESS | **(Optional)** (true/false) Enable or disable gzip backup compression - (Default False). |
| BACKUP_COMPRESS_LEVEL | **(Optional - default `9`)** Set the gzip level used for compression. |
| DATE_PREFIX | **(Optional)** (true/false) Enable or disable path prefix of `%Y/%m/%d/` format - (Default False). |
| AGE_PUBLIC_KEY | **(Optional)** Public key used to encrypt backup with [FiloSottile/age](https://github.com/FiloSottile/age). Leave blank to disable backup encryption. |
| SLACK_ENABLED | **(Optional)** (true/false) Enable or disable the Slack Integration (Default False). |
| SLACK_USERNAME | **(Optional)** (true/false) Username to use for the Slack Integration (Default: kubernetes-cloud-mysql-backup). |
Expand Down
13 changes: 10 additions & 3 deletions resources/perform-backup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/sh
#!/bin/sh

# Set the has_failed variable to false. This will change if any of the subsequent database backups/uploads fail.
has_failed=false
Expand All @@ -25,6 +25,13 @@ else
BACKUP_CREATE_DATABASE_STATEMENT=""
fi

# Add prefix to backup name
if [ "$DATE_PREFIX" = "true" ]; then
DATE_PREFIX=$(date +'%Y/%m/%d/')
else
DATE_PREFIX=""
fi

if [ "$TARGET_ALL_DATABASES" = "true" ]; then
# Ignore any databases specified by TARGET_DATABASE_NAMES
if [ ! -z "$TARGET_DATABASE_NAMES" ]
Expand Down Expand Up @@ -94,7 +101,7 @@ if [ "$has_failed" = false ]; then
fi

# Perform the upload to S3. Put the output to a variable. If successful, print an entry to the console and the log. If unsuccessful, set has_failed to true and print an entry to the console and the log
if awsoutput=$(aws $ENDPOINT s3 cp /tmp/$DUMP s3://$AWS_BUCKET_NAME$AWS_BUCKET_BACKUP_PATH/$DUMP 2>&1); then
if awsoutput=$(aws $ENDPOINT s3 cp /tmp/$DUMP s3://$AWS_BUCKET_NAME$AWS_BUCKET_BACKUP_PATH/$DATE_PREFIX$DUMP 2>&1); then
echo -e "Database backup successfully uploaded for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S')."
else
echo -e "Database backup failed to upload for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S'). Error: $awsoutput" | tee -a /tmp/kubernetes-cloud-mysql-backup.log
Expand All @@ -107,7 +114,7 @@ if [ "$has_failed" = false ]; then
if [ "$BACKUP_PROVIDER" = "gcp" ]; then

# Perform the upload to S3. Put the output to a variable. If successful, print an entry to the console and the log. If unsuccessful, set has_failed to true and print an entry to the console and the log
if gcpoutput=$(gsutil cp /tmp/$DUMP gs://$GCP_BUCKET_NAME$GCP_BUCKET_BACKUP_PATH/$DUMP 2>&1); then
if gcpoutput=$(gsutil cp /tmp/$DUMP gs://$GCP_BUCKET_NAME$GCP_BUCKET_BACKUP_PATH/$DATE_PREFIX$DUMP 2>&1); then
echo -e "Database backup successfully uploaded for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S')."
else
echo -e "Database backup failed to upload for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S'). Error: $gcpoutput" | tee -a /tmp/kubernetes-cloud-mysql-backup.log
Expand Down
5 changes: 2 additions & 3 deletions resources/slack-alert.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#/bin/sh

#!/bin/sh

# Check if there is any value in $2. If so, post an entry to the Slack channel with log information. If not, send a general message that all databases successfully completed
if [ "$(printf '%s' "$2")" == '' ]
Expand All @@ -10,4 +9,4 @@ PAYLOAD="payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNA
fi

# Send Slack message
curl -s -X POST --data-urlencode "$PAYLOAD" "$SLACK_WEBHOOK_URL" > /dev/null
curl -s -X POST --data-urlencode "$PAYLOAD" "$SLACK_WEBHOOK_URL" > /dev/null