Backup all MySQL databases in separate files

3 months, 1 week ago 0
Posted in: Programování
mysql -uroot -proot -e 'show databases' | while read dbname; do mysqldump -uroot -proot --complete-insert "$dbname" > "$dbname".sql; done
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/path-to-backup-dir/"
MYSQL_USER="root"
MYSQL=mysql
MYSQL_PASSWORD="root"
MYSQLDUMP=mysqldump
 
mkdir -p "$BACKUP_DIR/mysql"
 
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
 
for db in $databases; do
  $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz"
done

Comments are closed.