daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest May 31st, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
  3. db_host="localhost"
  4. db_user="backup"
  5. db_pass="XXXXXXXXXXXXXX"
  6. dbs=( drupal_voxmed onlinesurveys translations projects panel common )
  7. panel_empty_tables=( contacts contacts_addresses contacts_emails contacts_numbers contacts_others contacts_updates excluded_single_emails panel_audit access_contacts_bridge )
  8. now=$(date +%Y-%m-%d_%H:%M)
  9. backup_dir="/var/backups/env_sync"
  10.  
  11. #check and compress the dump
  12. function process_db_dump () {
  13.   if [ -f $1 ]
  14.     then
  15.       echo "Done - $(date)"
  16.       echo -n "Compressing $db dump - $(date) ... "
  17.       gzip -f $1
  18.       if [ -f $1.gz ]
  19.         then
  20.           echo "Done - $(date)... "
  21.         else
  22.           echo "ERROR $db not compressed - $(date)"
  23.       fi
  24.     else
  25.       echo "ERROR $db not backed up - $(date)"
  26.   fi
  27. }
  28.  
  29. #prep our location
  30. mkdir -p $backup_dir && chown mysql $backup_dir && find $backup_dir -type f -name *.sql.gz | xargs rm -fv
  31.  
  32. for db in ${dbs[@]}
  33.   do
  34.     now=$(date +%Y-%m-%d_%H:%M)
  35.     db_file="$db-$now.sql"
  36.     if [[ "$db" =~ (panel) ]]
  37.       then
  38.         echo -n "Dumping $db - $(date) ... "
  39.         mysqldump -q -h $db_host -u $db_user -p$db_pass $(for table in ${panel_empty_tables[@]}; do echo -n "--ignore-table=$db.$table "; done) $db > $backup_dir/$db_file
  40.         mysqldump -q -h $db_host -u $db_user -p$db_pass --no-data $db $(for table in ${panel_empty_tables[@]}; do echo -n "$table "; done) >> $backup_dir/$db_file
  41.         process_db_dump "$backup_dir/$db_file"
  42.       else
  43.         echo -n "Dumping $db - $(date)... "
  44.         mysqldump -q -h $db_host -u $db_user -p$db_pass $db > $backup_dir/$db_file
  45.         process_db_dump "$backup_dir/$db_file"
  46.     fi
  47. 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