Created
March 3, 2018 12:11
-
-
Save fracz/3c58c9981562655a3e36c02315a12014 to your computer and use it in GitHub Desktop.
Automatic dockerized SUPLA MySQL database backup to Google Drive
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
#!/usr/bin/env bash | |
# Sample crontab: 0 */2 * * * /home/unicorn/backup.sh > /home/unicorn/backup.log 2>&1 | |
NOW=$(date +"%Y%m%d%H%M%S") | |
BACKUP_FILE=supla-$NOW.sql | |
GDRIVE_DIR=0B0OnuB36CtoeknVRX2xRbS1sT1E | |
SUPLA_PATH=/var/www/supla-docker | |
BACKUP_EXPIRATION_DAYS=7 | |
cd "$(dirname "$0")" | |
source $SUPLA_PATH/docker/.env && \ | |
docker exec supla-db mysqldump -u root --password="$DB_PASSWORD" supla > $BACKUP_FILE && \ | |
gzip $BACKUP_FILE && \ | |
gdrive upload $BACKUP_FILE.gz --parent $GDRIVE_DIR --delete | |
sleep 5 | |
OLD_BACKUPS=$(date -u -d "${BACKUP_EXPIRATION_DAYS} days ago" +"%Y-%m-%dT%H:%M:%SZ") | |
OBSOLETE_BACKUPS=$(gdrive list -m 1000 --query \ | |
"(('${GDRIVE_DIR}' in parents) and trashed=false and modifiedTime < '$OLD_BACKUPS'" \ | |
--order "modifiedTime asc" --no-header | cut -d ' ' -f1) | |
while read -r OBSOLETE_BACKUP_ID; do | |
if [ ! -z "$OBSOLETE_BACKUP_ID" ]; then | |
echo Deleting $OBSOLETE_BACKUP_ID | |
gdrive delete $OBSOLETE_BACKUP_ID | |
fi | |
done <<< "$OBSOLETE_BACKUPS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is an error on line 23. Should:
" ((' ${GDRIVE_DIR} ' w rodzicach) i trasshed=false i updatedTime < ' $OLD_BACKUPS ') " \
Greetings.