Skip to content
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
19 changes: 19 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mariadb:10.5.12

ENV MYSQL_ROOT_PASSWORD=secret
ENV MYSQL_USER=username
ENV MYSQL_PASSWORD=password
ENV MYSQL_DATABASE=wordpress

COPY dump.sh /usr/local/bin/dump.sh
COPY restore.sh /usr/local/bin/restore.sh
COPY bro.cnf /home

# Install cron
RUN apt-get update && apt-get install -y cron

RUN chmod +x /usr/local/bin/dump.sh
RUN chmod +x /usr/local/bin/restore.sh

RUN echo "0 2 * * * /usr/local/bin/dump.sh" | crontab -
RUN echo "30 3 * * 6 /usr/local/bin/backup.sh" | crontab -
6 changes: 6 additions & 0 deletions db/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Run mysqlbackup command
mariabackup --defaults-extra-file=/home/bro.cnf \
--backup \
--target-dir=/etc/mysql/conf.d/backup/
11 changes: 11 additions & 0 deletions db/bro.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[mysqldump] # NEEDED FOR DUMP
user=username
password=password

[mysql] # NEEDED FOR RESTORE
user=username
password=password

[mariabackup]
user=root
password=secret
11 changes: 11 additions & 0 deletions db/dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Define variables
DB_NAME="wordpress"

# Set the current date for the dump file
DATE=$(date +"%Y%m%d_%H%M%S")
DUMP_FILE="/etc/mysql/conf.d/dumps/${DB_NAME}_dump_$DATE.sql"

# Run mysqldump command
mysqldump --defaults-extra-file=/home/bro.cnf "$DB_NAME" > "$DUMP_FILE"
9 changes: 9 additions & 0 deletions db/restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

backup=$(ls -t1 /etc/mysql/conf.d/backups | head -n 1)

if [ -z ${backup} ]; then
echo "No Backups found!"
else
mysql --defaults-extra-file=/home/bro.cnf wordpress < /etc/mysql/conf.d/backups/${backup}
fi
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,24 @@
# and compose your stack by running
# docker compose up -d
################################################################################

version: "2"
services:
data:
build: data

db:
build: db
volumes_from:
- data
volumes:
- ~/dockerfiles/etc/mysql/conf.d:/etc/mysql/conf.d

wp:
image: wordpress:5.8.1-php8.0-apache
ports:
- "80:80"
links:
- db:mysql
volumes:
- ~/dockerfiles/wp-content:/var/www/html/wp-content
20 changes: 20 additions & 0 deletions docker-compose.yml-cron-backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "2"
services:
data:
build: data

db:
build: db
volumes_from:
- data
volumes:
- ~/dockerfiles/etc/mysql/conf.d:/etc/mysql/conf.d

wp:
image: wordpress:5.8.1-php8.0-apache
ports:
- "80:80"
links:
- db:mysql
volumes:
- ~/dockerfiles/wp-content:/var/www/html/wp-content