Last active
February 11, 2021 15:13
-
-
Save Pamps/a8f39933ad3d2570003abab7efde3b18 to your computer and use it in GitHub Desktop.
Dump MySql (MAMP) database tables to Dropbox for daily backups.
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 | |
#-------------------------------------------------------------------------- | |
# 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