Note to self — so I don’t have to think about it again next time.
#!/bin/bash export MYSQL_PWD=myrootpassword BACKUP_DIR=/mnt/backups/mysql_backups DATE=`date -I` for dbname in `mysql -uroot --batch --skip-column-names -e "show databases;" | grep -v information_schema`; do /usr/local/bin/mysqldump -u root $dbname | gzip -9 > $BACKUP_DIR/$dbname-$DATE.sql.gz done # Clear backups older than 7 days /usr/local/bin/find $BACKUP_DIR/*.sql.gz -mtime +7 -delete
Edited to include compression. Remember to include full paths if you’re running it from a crontab, just in case.
Post a Comment