Skip to content

Instantly share code, notes, and snippets.

@m0r13
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save m0r13/11109358 to your computer and use it in GitHub Desktop.

Select an option

Save m0r13/11109358 to your computer and use it in GitHub Desktop.
#!/bin/bash
mysql_user=user
mysql_pwd=pwd
databases=$(echo "show databases;" | sudo mysql -u "$mysql_user" -p "$mysql_pwd" -B | tail -n +2)
date=$(date +%Y-%m-%d_%H-%M-%S)
for database in $databases;
do
file=/var/db/backup/$database.$date.sql.gz
mysqldump -u "$mysql_user" -p "$mysql_pwd" $database | gzip -9 > $file
done
find /var/db/backup/ -mtime +10 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment