Created
May 24, 2024 04:08
-
-
Save hgc81538/89749482e7b01b34bc4d76ff9cf3b1c3 to your computer and use it in GitHub Desktop.
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/sh | |
NOW=$(date +'%Y-%m-%d') | |
BACKUP_DIR="/path/to/backup" | |
MYSQL_USER="root" | |
# mysql | |
# https://mensfeld.pl/2013/04/backup-mysql-dump-all-your-mysql-databases-in-separate-files/ | |
databases=`/usr/bin/mysql --user=$MYSQL_USER -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql|test|phpmyadmin|sys)"` | |
for db in $databases; do | |
if [ "$db" != "" ] ; then | |
/usr/bin/mysqldump --user=$MYSQL_USER --databases $db | gzip > "$BACKUP_DIR/mysql-${db}-$NOW.sql.gz" | |
fi | |
done | |
# keep for 14 days and remove old backup | |
find $BACKUP_DIR/ -mindepth 1 -mtime +14 -delete; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment