Skip to content

Instantly share code, notes, and snippets.

@josectheone
Created October 14, 2019 11:25
Show Gist options
  • Save josectheone/8e735181d7b4ae784700cd5cef10f4f3 to your computer and use it in GitHub Desktop.
Save josectheone/8e735181d7b4ae784700cd5cef10f4f3 to your computer and use it in GitHub Desktop.
Gdrive backup shell script
#!/bin/bash
# Set date variable
date=$(date +%Y%m%d-%H%M)
# Run mysqldump command inside mariadb container
docker exec -u root moodle_db bash -c 'mysqldump -u root -e -x -A | gzip > /bitnami/backup.sql.gz'
# Move backup file to backup directory
mv /var/lib/docker/volumes/moodle_db/_data/backup.sql.gz /opt/backups/backup-$date.sql.gz
# Compress moodledata folder
tar -zcf /opt/backups/moodledata-$date.tar.gz /var/lib/docker/volumes/moodle_app/_data/moodle/ead/moodledata
# Keep only 30 days of backups
find /opt/backups/ -type f -mtime +7 -delete
# Sync with Google drive
gdrive sync upload --delete-extraneous /opt/backups/ <account_key_here>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment