Skip to content

Instantly share code, notes, and snippets.

@zach-adams
Created July 15, 2015 17:07
Show Gist options
  • Save zach-adams/77bc44e094cce738beb0 to your computer and use it in GitHub Desktop.
Save zach-adams/77bc44e094cce738beb0 to your computer and use it in GitHub Desktop.
A copy of the db_backup script that automatically copies the backups to the sync folder
#!/bin/bash
#
# Create individual SQL files for each database. These files
# are imported automatically during an initial provision if
# the databases exist per the import-sql.sh process.
mysql -e 'show databases' | \
grep -v -F "information_schema" | \
grep -v -F "performance_schema" | \
grep -v -F "mysql" | \
grep -v -F "test" | \
grep -v -F "Database" | \
while read dbname; do mysqldump -uroot "$dbname" > /srv/database/backups/"$dbname".sql && echo "Database $dbname backed up..."; done
# Copy backups to sync folder
mkdir -p /srv/database/sync/
cp /srv/database/backups/. /srv/database/sync/ -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment