From 9a51cbd666a0bafc5bc83fbaf420e1e8db9d59ea Mon Sep 17 00:00:00 2001 From: lunchbox Date: Fri, 31 Mar 2023 11:02:46 -0500 Subject: [PATCH] db backups --- mariadb-backups/docker-compose.yaml | 20 ++++++++++++++++++++ mariadb-backups/sample.env | 2 ++ postgres-backup/docker-compose.yaml | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 mariadb-backups/docker-compose.yaml create mode 100644 mariadb-backups/sample.env create mode 100644 postgres-backup/docker-compose.yaml diff --git a/mariadb-backups/docker-compose.yaml b/mariadb-backups/docker-compose.yaml new file mode 100644 index 0000000..63f0c32 --- /dev/null +++ b/mariadb-backups/docker-compose.yaml @@ -0,0 +1,20 @@ +# docker-compose.yml file +version: '3.8' +services: + db: + image: mariadb:latest + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: example + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + volumes: + - ./data:/var/lib/mysql + - ./backups:/backups + ports: + - "3306:3306" + command: > + bash -c "while true; do + mysqldump -u root -p${MYSQL_ROOT_PASSWORD} --all-databases | gzip > /backups/db_$(date +%Y%m%d%H%M%S).sql.gz; + sleep 24h; + done" \ No newline at end of file diff --git a/mariadb-backups/sample.env b/mariadb-backups/sample.env new file mode 100644 index 0000000..2a7ff32 --- /dev/null +++ b/mariadb-backups/sample.env @@ -0,0 +1,2 @@ +MYSQL_USER=yourusername +MYSQL_PASSWORD=yourpassword \ No newline at end of file diff --git a/postgres-backup/docker-compose.yaml b/postgres-backup/docker-compose.yaml new file mode 100644 index 0000000..51bb12c --- /dev/null +++ b/postgres-backup/docker-compose.yaml @@ -0,0 +1,20 @@ +version: '3.8' +services: + db: + image: postgres:latest + restart: unless-stopped + environment: + POSTGRES_PASSWORD: example + POSTGRES_USER: yourusername + POSTGRES_DB: yourdatabase + volumes: + - ./data:/var/lib/postgresql/data + - ./backups:/backups + ports: + - "5432:5432" + command: > + bash -c "while true; do + pg_dumpall -U ${POSTGRES_USER} -f /backups/db_$(date +%Y%m%d%H%M%S).sql; + gzip /backups/db_$(date +%Y%m%d%H%M%S).sql; + sleep 24h; + done" \ No newline at end of file