2014-11-27 00:27:17 +10:00
|
|
|
#!/bin/bash
|
|
|
|
bakdate=$(date +%Y%m%d%H%M)
|
|
|
|
|
|
|
|
DBUSER='dbbackup'
|
|
|
|
DBPASS='EWFfP3GZsqr427Yj'
|
|
|
|
BACKUPDIR='/BACKUP/db/'
|
|
|
|
|
2015-06-13 14:17:16 +10:00
|
|
|
rotate_backups() {
|
2015-06-15 15:56:36 +10:00
|
|
|
find $BACKUPDIR -type f -mtime +7 -exec rm -frv {} \;
|
2015-06-13 14:17:16 +10:00
|
|
|
|
2015-06-15 15:56:36 +10:00
|
|
|
}
|
2015-06-13 14:17:16 +10:00
|
|
|
|
|
|
|
rotate_backups
|
|
|
|
|
2014-11-27 00:27:17 +10:00
|
|
|
databases=`mysql --user=$DBUSER --password=$DBPASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
|
|
|
|
|
|
|
|
for db in $databases; do
|
|
|
|
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
|
|
|
|
echo "Dumping database: $db"
|
2015-03-30 22:33:53 +10:00
|
|
|
mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.`date +%Y%m%d`.sql
|
2014-11-27 00:27:17 +10:00
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
2015-06-13 14:17:16 +10:00
|
|
|
|
|
|
|
|