Capoeirista

BackupDB

Apr 22nd, 2021
828
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
  3.  
  4. alias mysql='mysql --defaults-file=/root/.my.cnf'
  5. alias mysqldump='mysqldump --defaults-file=/root/.my.cnf'
  6.  
  7. dest="/root/backup_mysql"
  8. date=$(date +%d-%m-%Y)
  9. time=$(date +%H-%M-%S)
  10.  
  11. find $dest -type d \( -name "*-1[^5]" -o -name "*-[023]?" \) -ctime +30 -exec rm -R {} \; 2>&1
  12. find $dest -type d -name "*-*" -ctime +180 -exec rm -R {} \; 2>&1
  13. mkdir $dest/"$date" 2>&1
  14.  
  15. for dbname in $(echo show databases | mysql | grep -v Database); do
  16.     case $dbname in
  17.         information_schema)
  18.             continue ;;
  19.         mysql)
  20.             continue ;;
  21.         performance_schema)
  22.             continue ;;
  23.         test)
  24.             continue ;;
  25.         *) mysqldump --databases --skip-comments --default-character-set=utf8mb4 "$dbname" > $dest/"$date"/"$dbname".sql ;;
  26. # Если нужно архивировать
  27. #         *) mysqldump --databases --skip-comments -u$userDB -p$passwordDB $dbname | gzip > $dest/$fdate/$dbname.sql.gz ;;
  28.     esac
  29. done;
  30.  
  31. cd $dest/$date || exit
  32. tar -cjpf "$time".tar.bz2 --remove-files --absolute-names "$time"
  33. #rm -rf "${time:?}"/
  34. find $dest/*.tar.bz2 -mtime +30 -delete
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×