Advertisement
Guest User

Untitled

a guest
Oct 18th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DB_BACKUP="~/backups/mysql_backup/`date +%Y-%m-%d`"
  4. DB_USER="user"
  5. DB_PASSWD="thisisthebestpasswordintheworld"
  6. HN=`hostname | awk -F. '{print $1}'`
  7.  
  8. # Create the backup directory
  9. mkdir -p $DB_BACKUP
  10.  
  11. # Remove backups older than 10 days
  12. find ~/backups/mysql_backup/ -maxdepth 1 -type d -mtime +10 -exec rm -rf {} \;
  13.  
  14. # Backup each database on the system
  15. for db in $(mysql --user=$DB_USER --password=$DB_PASSWD -e 'show databases' -s --skip-column-names|grep -viE '(staging|performance_schema|information_schema)');
  16. do mysqldump --user=$DB_USER --password=$DB_PASSWD --events --opt --single-transaction $db | gzip > "$DB_BACKUP/mysqldump-$HN-$db-$(date +%Y-%m-%d).gz";
  17. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement