Skip to content

Commit

Permalink
feat: add mysql script
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBabel committed Sep 8, 2021
1 parent e2e800d commit 2aa22ce
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM alexbabel/s3backup:0.11.2

RUN apk add --no-cache mongodb-tools postgresql-client
RUN apk add --no-cache mongodb-tools postgresql-client mysql-client python3 bash && rm -f /var/cache/apk/*

COPY mongodb.sh /usr/bin/mongodb.sh
COPY postgresql.sh /usr/bin/postgresql.sh
COPY mysql.sh /usr/bin/mysql.sh
COPY mysql-cmd.py /usr/bin/mysql-cmd.py

CMD /usr/bin/mongodb.sh
4 changes: 2 additions & 2 deletions mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
DEST=/backup

# Create backup dir (-p to avoid warning if already exists)
/bin/mkdir -p $DEST
/bin/mkdir -p "$DEST"

# Log
echo "Backing up mongodb";

# Dump from mongodb host into backup directory
/usr/bin/mongodump --uri=$DATABASE_URL -o $DEST
/usr/bin/mongodump "--uri=$DATABASE_URL" -o "$DEST"

# Run dokku backup script
/usr/bin/backup.sh
9 changes: 9 additions & 0 deletions mysql-cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3

import os
from urllib.parse import urlparse

uri = os.getenv('DATABASE_URL')
result = urlparse(uri)

print(f"/usr/bin/mysqldump -u {result.username} -p {result.password} -d {(result.path or '').replace('/', '')} {result.hostname}:{result.port if result.port else 3306}")
16 changes: 16 additions & 0 deletions mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# # Backup directory
DEST=/backup

# Create backup dir (-p to avoid warning if already exists)
/bin/mkdir -p "$DEST"

# Log
echo "Backing up mysql"

# Dump from postgresql host into backup directory
eval "$(python3 /usr/bin/mysql-cmd.py)"

# Run dokku backup script
/usr/bin/backup.sh
4 changes: 2 additions & 2 deletions postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
DEST=/backup

# Create backup dir (-p to avoid warning if already exists)
/bin/mkdir -p $DEST
/bin/mkdir -p "$DEST"

# Log
echo "Backing up postgresql";

# Dump from postgresql host into backup directory
/usr/bin/pg_dump -Fd --no-acl --no-owner $DATABASE_URL -f $DEST
/usr/bin/pg_dump -Fd --no-acl --no-owner "$DATABASE_URL" -f "$DEST"

# Run dokku backup script
/usr/bin/backup.sh

0 comments on commit 2aa22ce

Please sign in to comment.