Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.aes
codeship-services.yml
codeship-steps.yml
dockercfg
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ local.env

vendor/
*.aes

dockercfg
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mysql-backup-restore
Service to backup and/or restore mysql databases using S3
Service to backup and/or restore mysql databases to/from S3

## How to use it
1. Create an S3 bucket to hold your backups
Expand All @@ -8,34 +8,45 @@ Service to backup and/or restore mysql databases using S3
4. Run a backup and check your bucket for that backup

### Environment variables
`MODE=[backup|restore]`
`MODE` Valid values: `backup`, `restore`

`DB_NAMES=name1 name2 name3 ...`
`DB_NAMES` list of the database names

`MYSQL_USER=`
`MYSQL_USER` user that accesses the database

`MYSQL_PASSWORD=`
`MYSQL_PASSWORD` password for the `MYSQL_USER`

`MYSQL_DUMP_ARGS=` (optional) additional arguments to the mysqldump command, e.g., `--max_allowed_packet=50M`
`MYSQL_DUMP_ARGS` (optional) additional arguments to the mysqldump command, e.g., `--max_allowed_packet=50M`

`AWS_ACCESS_KEY=` used for S3 interactions
`AWS_ACCESS_KEY` used for S3 interactions

`AWS_SECRET_KEY=` used for S3 interactions
`AWS_SECRET_KEY` used for S3 interactions

`S3_BUCKET=` _e.g., s3://database-backups_ **NOTE: no trailing slash**
`S3_BUCKET` e.g., _s3://database-backups_ **NOTE: no trailing slash**

>**It's recommended that your S3 bucket have versioning turned on.**

## Docker Hub
This image is built automatically on Docker Hub as [silintl/mysql-backup-restore](https://hub.docker.com/r/silintl/mysql-backup-restore/)
This image is built automatically on Docker Hub as [silintl/mysql-backup-restore](https://hub.docker.com/r/silintl/mysql-backup-restore/).

## Playing with it locally
You'll need [Docker](https://www.docker.com/get-docker) and [Make](https://www.gnu.org/software/make/)

1. `cp local.env.dist local.env` and supply variables
2. Ensure you have a `gz` dump in your S3 bucket to be used for testing. A test database is provided as part of this project in the `test` folder.
3. `make`

A UI into the local database will then be running at [http://localhost:8001](http://localhost:8001)

A couple of test databases are provided in the `test` folder if needed.
You'll need [Docker](https://www.docker.com/get-docker), [Docker Compose](https://docs.docker.com/compose/install/), and [Make](https://www.gnu.org/software/make/).

1. cd .../mysql-backup-restore
2. mkdir ./mybackups
3. cp -p test/world.sql.gz ./mybackups
4. `make db` # creates the MySQL DB server
5. `make restore` # restores the DB dump file
6. `docker ps -a` # get the Container ID of the exited restore container
7. `docker logs <containerID>` # review the restoration log messages
8. `make backup` # create a new DB dump file
9. `docker ps -a` # get the Container ID of the exited backup container
10. `docker logs <containerID>` # review the backup log messages
11. `make restore` # restore the DB dump file from the new backup
12. `docker ps -a` # get the Container ID of the exited restore container
13. `docker logs <containerID>` # review the restoration log messages
14. `make clean` # remove containers and network
15. `docker volume ls` # find the volume ID of the MySQL data container
16. `docker volume rm <volumeID>` # remove the data volume
17. `docker images` # list existing images
18. `docker image rm <imageID ...>` # remove images no longer needed
5 changes: 5 additions & 0 deletions codeship-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
app:
build:
image: silintl/mysql-backup-restore
dockerfile: ./Dockerfile
cached: true
17 changes: 17 additions & 0 deletions codeship-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- name: push_branch
service: app
type: push
image_name: silintl/mysql-backup-restore
image_tag: "{{.Branch}}"
exclude: (master|main|snyk*)
registry: https://index.docker.io/v1/
encrypted_dockercfg_path: dockercfg.encrypted

- name: push_latest
service: app
type: push
image_name: silintl/mysql-backup-restore
image_tag: "latest"
tag: main
registry: https://index.docker.io/v1/
encrypted_dockercfg_path: dockercfg.encrypted
2 changes: 2 additions & 0 deletions dockercfg.encrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
codeship:v2
BScPjmqUw7hFx9ZW8TpjL9cIXw+1Faw6Xo/kOFPyh8Lr6qoSnpqL9wU/OW2yObPm9igjCqTxCIDWfCE/5sr3qVo2RCI2cI73zrRIyUReJrORwIVc0wxGauwi3ctj5zSCSlNOcTI5SoY736UhZ1XIPLeHnwI1Y/eA3MRG9D2inlf2VsZNgw0D2pddTMRfQVzSmz4dPGg2MceRSqUjf+cGomfBiW/ZXNih7jNl+2DlwD5s/fJBYk+OKfPnwoq6/no489YZBksMttfZtkt/2KG+teiXCB/gJ43OUYhj6jucZP36RHpkcjTbD+uJ88VJ
4 changes: 4 additions & 0 deletions test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The example database was originally downloaded from the web and placed
in this directory. You can find the original here:

https://dev.mysql.com/doc/world-setup/en/
Binary file removed test/employees.sql.gz
Binary file not shown.