daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. TIMESTAMP=$(date +"%F")
  4. BACKUP_TOP_DIR="/mnt/mysql_backup"
  5. BACKUP_DIR="$BACKUP_TOP_DIR/$TIMESTAMP"
  6. MYSQL_USER="root"
  7. MYSQL=/usr/bin/mysql
  8. MYSQL_PASSWORD="2aaHfUGrQFg3"
  9. MYSQLDUMP=/usr/bin/mysqldump
  10. IONICE="ionice -c 2 -n 6"
  11. NICE="nice -n 10"
  12.          
  13. mkdir -p "$BACKUP_DIR"
  14.          
  15. # clean old backups
  16. find "$BACKUP_TOP_DIR" -maxdepth 1 -type d -mtime +14 -exec rm -rf {} +
  17.  
  18. databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
  19.  
  20. echo "Starting $0 on $TIMESTAMP"
  21. for db in $databases; do
  22.   echo "* backing up $db"
  23.   $IONICE $NICE $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | pigz -9 > "$BACKUP_DIR/$db.gz"
  24. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top