Last active
November 12, 2020 18:55
-
-
Save frankmarineau/64a8076097427453c990db4eb82a52d3 to your computer and use it in GitHub Desktop.
Small shell script that backs up dokku databases to Google Cloud Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Backing up dokku databases to GCS ..." | |
dt=$(date +"%Y-%m-%d") | |
TEMP_BACKUP_PATH=/tmp/db-backups | |
REMOTE_BACKUP_PATH=gs://dokku-backups/$(date +"%Y")/$(date +"%B") | |
export_dbs() { | |
dbs=$(dokku $1:list | grep running | cut -f1 -d' ') | |
for db in $dbs | |
do | |
echo " backing up $db ..." | |
mkdir -p $TEMP_BACKUP_PATH/$db | |
f=$db/$dt-$db.tar | |
rm -f $f | |
dokku $1:export $db > $TEMP_BACKUP_PATH/$f | |
gsutil cp -z 'tar' $TEMP_BACKUP_PATH/$f $REMOTE_BACKUP_PATH/$1/$f | |
done | |
} | |
export_dbs mongo | |
export_dbs postgres | |
export_dbs mariadb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by Daniel Doubrovkine's great blog post.