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

Commit

Permalink
Merge pull request #4 from benjamin-maynard/re-name
Browse files Browse the repository at this point in the history
Perform rename from aws-database-backup to kubernetes-mysql-backup
  • Loading branch information
benjamin-maynard authored May 21, 2019
2 parents b6a30b4 + 3002424 commit 5b4656d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v2.0.1] - 21-05-2019
### Renamed to kubernetes-mysql-backup
- Renamed to kubernetes-s3-mysql-backup from aws-database-backup to better describe function

## [v2.0.0] - 16-12-2018
### Fix issue with Slack Alerts
- Implemented the ability to backup multiple databases from a single host
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apk -v --update add \
# Set Default Environment Variables
ENV TARGET_DATABASE_PORT=3306
ENV SLACK_ENABLED=false
ENV SLACK_USERNAME=aws-database-backup
ENV SLACK_USERNAME=kubernetes-s3-mysql-backup

# Copy Slack Alert script and make executable
COPY resources/slack-alert.sh /
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# aws-database-backup
# kubernetes-s3-mysql-backup

aws-database-backup is a container image based on Alpine Linux. This container is designed to run in Kubernetes as a cronjob to perform automatic backups of MySQL databases to Amazon S3. It was created to meet my requirements for regular and automatic database backups. Having started with a relatively basic feature set, it is gradually growing to add more and more features.
kubernetes-s3-mysql-backup is a container image based on Alpine Linux. This container is designed to run in Kubernetes as a cronjob to perform automatic backups of MySQL databases to Amazon S3. It was created to meet my requirements for regular and automatic database backups. Having started with a relatively basic feature set, it is gradually growing to add more and more features.

Currently, aws-database-backup supports the backing up of MySQL Databases. It can perform backups of multiple MySQL databases from a single database host. When triggered, a full database dump is performed using the `mysqldump` command for each configured database. The backup(s) are then uploaded to an Amazon S3 Bucket. aws-database-backup features Slack Integration, and can post messages into a channel detailing if the backup(s) were successful or not.
Currently, kubernetes-s3-mysql-backup supports the backing up of MySQL Databases. It can perform backups of multiple MySQL databases from a single database host. When triggered, a full database dump is performed using the `mysqldump` command for each configured database. The backup(s) are then uploaded to an Amazon S3 Bucket. kubernetes-s3-mysql-backup features Slack Integration, and can post messages into a channel detailing if the backup(s) were successful or not.

Over time, aws-database-backup will be updated to support more features and functionality. I currently use this container as part of my Kubernetes Architecture which you can read about [here](https://benjamin.maynard.io/this-blog-now-runs-on-kubernetes-heres-the-architecture/).
Over time, kubernetes-s3-mysql-backup will be updated to support more features and functionality. I currently use this container as part of my Kubernetes Architecture which you can read about [here](https://benjamin.maynard.io/this-blog-now-runs-on-kubernetes-heres-the-architecture/).

All changes are captured in the [changelog](CHANGELOG.md), which adheres to [Semantic Versioning](https://semver.org/spec/vadheres2.0.0.html).


## Environment Variables

The below table lists all of the Environment Variables that are configurable for aws-database-backup.
The below table lists all of the Environment Variables that are configurable for kubernetes-s3-mysql-backup.

| Environment Variable | Purpose |
| --------------------------- |------------------------------------------------------------------------------------------------------------------|
Expand All @@ -26,23 +26,23 @@ The below table lists all of the Environment Variables that are configurable for
| TARGET_DATABASE_USER | **(Required)** Username to authenticate to the database with. |
| TARGET_DATABASE_PASSWORD | **(Required)** Password to authenticate to the database with. Should be configured using a Secret in Kubernetes. |
| 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: aws-database-backup). |
| SLACK_USERNAME | **(Optional)** (true/false) Username to use for the Slack Integration (Default: kubernetes-s3-mysql-backup). |
| SLACK_CHANNEL | **(Required if Slack enabled)** Slack Channel the WebHook is configured for. |
| SLACK_WEBHOOK_URL | **(Required if Slack enabled)** What is the Slack WebHook URL to post to? Should be configured using a Secret in Kubernetes. |


## Slack Integration

aws-database-backup supports posting into Slack after each backup job completes. The message posted into the Slack Channel varies as detailed below:
kubernetes-s3-mysql-backup supports posting into Slack after each backup job completes. The message posted into the Slack Channel varies as detailed below:

* If the backup job is **SUCCESSFUL**: A generic message will be posted into the Slack Channel detailing that all database backups successfully completed.
* If the backup job is **UNSUCCESSFUL**: A message will be posted into the Slack Channel with a detailed error message for each database that failed.

In order to configure aws-database-backup to post messages into Slack, you need to create an [Incoming WebHook](https://api.slack.com/incoming-webhooks). Once generated, you can configure aws-database-backup using the environment variables detailed above.
In order to configure kubernetes-s3-mysql-backup to post messages into Slack, you need to create an [Incoming WebHook](https://api.slack.com/incoming-webhooks). Once generated, you can configure kubernetes-s3-mysql-backup using the environment variables detailed above.

## Configuring the S3 Bucket & AWS IAM User

aws-database-backup performs a backup to the same path, with the same filename each time it runs. It therefore assumes that you have Versioning enabled on your S3 Bucket. A typical setup would involve S3 Versioning, with a Lifecycle Policy.
kubernetes-s3-mysql-backup performs a backup to the same path, with the same filename each time it runs. It therefore assumes that you have Versioning enabled on your S3 Bucket. A typical setup would involve S3 Versioning, with a Lifecycle Policy.

An IAM Users should be created, with API Credentials. An example Policy to attach to the IAM User (for a minimal permissions set) is as follows:

Expand Down Expand Up @@ -110,7 +110,7 @@ spec:
spec:
containers:
- name: my-database-backup
image: benjaminmaynard/aws-database-backup
image: benjaminmaynard/kubernetes-s3-mysql-backup
imagePullPolicy: Always
env:
- name: AWS_ACCESS_KEY_ID
Expand Down
8 changes: 4 additions & 4 deletions resources/perform-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ do
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/aws-database-backup.log
echo -e "Database backup failed to upload for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S'). Error: $awsoutput" | tee -a /tmp/kubernetes-s3-mysql-backup.log
has_failed=true
fi

else
echo -e "Database backup FAILED for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S'). Error: $sqloutput" | tee -a /tmp/aws-database-backup.log
echo -e "Database backup FAILED for $CURRENT_DATABASE at $(date +'%d-%m-%Y %H:%M:%S'). Error: $sqloutput" | tee -a /tmp/kubernetes-s3-mysql-backup.log
has_failed=true
fi

Expand All @@ -41,13 +41,13 @@ then
if [ "$SLACK_ENABLED" = true ]
then
# Put the contents of the database backup logs into a variable
logcontents=`cat /tmp/aws-database-backup.log`
logcontents=`cat /tmp/kubernetes-s3-mysql-backup.log`

# Send Slack alert
/slack-alert.sh "One or more backups on database host $TARGET_DATABASE_HOST failed. The error details are included below:" "$logcontents"
fi

echo -e "aws-database-backup encountered 1 or more errors. Exiting with status code 1."
echo -e "kubernetes-s3-mysql-backup encountered 1 or more errors. Exiting with status code 1."
exit 1

else
Expand Down

0 comments on commit 5b4656d

Please sign in to comment.