daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Aug 13th, 2016 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Configuration.
  2. date=`date +%Y-%m-%d`
  3. bk_dest='/var/archives/mysql'
  4. log_file=$bk_dest/bk_mysql-${date}.log
  5. mysql_cmd='/usr/bin/mysql'
  6. mysqldump_cmd='/usr/bin/mysqldump'
  7. dbuser=root
  8. dbpass=`cat /etc/.mysqlpasswd`
  9.  
  10.  
  11. databases=(`echo 'show databases;' | $mysql_cmd -u ${dbuser} --password=${dbpass} | grep -v ^Database$`)
  12.  
  13. for d in "${databases[@]}"; do
  14.       if [[ $d != 'tmp' && $d != 'test' ]]
  15.       then
  16.             echo "DATABASE ${d}" >> $log_file
  17.             path="${bk_dest}/${date}"
  18.             mkdir -p ${path}
  19.             ${mysqldump_cmd} --user=${dbuser} --password=${dbpass} --opt --databases ${d} | bzip2 -c > ${path}/${d}.sql.bz2
  20.        fi
  21. done
  22.  
  23. # delete old dumps (retain 5 days)
  24. find ${bk_dest} -mtime +5 -exec rm {} \;
  25.  
  26. echo "" >> $log_file
  27. echo Disk Space Report: >> $log_file
  28. echo -------------------------------------- >> $log_file
  29. du -h --max-depth=1 $bk_dest >> $log_file
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