Skip to content

Instantly share code, notes, and snippets.

@Pamps
Last active February 11, 2021 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pamps/a8f39933ad3d2570003abab7efde3b18 to your computer and use it in GitHub Desktop.
Save Pamps/a8f39933ad3d2570003abab7efde3b18 to your computer and use it in GitHub Desktop.
Dump MySql (MAMP) database tables to Dropbox for daily backups.
#!/bin/bash
#--------------------------------------------------------------------------
# Daily MySQL dump on OSX to use in conjuction with Time Machine
#
# 1) Save this file in some appropriate location like /usr/sbin/dbbackup.sh
# 2) Make sure it is executable: sudo chmod +x /usr/sbin/dbbackup.sh
# 3) Create the backup directory: mkdir ~/dbdumps
# 4) Create the cron entry to run it daily by executing the following:
# sudo echo "47 5 * * * /usr/sbin/dbbackup.sh" >> /usr/lib/cron/tabs/root
# (This will run the script at 05:47 am each day)
#
#--------------------------------------------------------------------------
# Edit these values for your local configuration
CMD_DUMP=/Applications/MAMP/Library/bin/mysqldump
MYSQLDIR=/Applications/MAMP/db/mysql57
BACKUPDIR=/Users/darren/Dropbox/Websites/MySql/Backups
MYSQLUSER="root"
MYSQLPASS="root"
ls -1 $MYSQLDIR | while read db;
do
if [ -d $MYSQLDIR/$db ]; then
echo -n dumping MySQL database $db ...
$CMD_DUMP -u $MYSQLUSER --password=$MYSQLPASS $db > $BACKUPDIR/$db.sql;
zip $BACKUPDIR/$db.zip $BACKUPDIR/$db.sql
rm $BACKUPDIR/$db.sql
echo done.
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment