User Tools

Site Tools


mysql_backup_simple

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
mysql_backup_simple [2014/09/02 00:09]
kyxap
mysql_backup_simple [2015/04/04 10:35]
kyxap
Line 6: Line 6:
 # CLI args: none # CLI args: none
  
-set -e # exit on error+#exit on error 
 +set -e
  
 LANG=C LANG=C
Line 17: Line 18:
  
 DAYS=7 DAYS=7
-DB="production development"+DB="all"
 OPTS="​--order-by-primary --add-drop-database"​ OPTS="​--order-by-primary --add-drop-database"​
  
Line 38: Line 39:
 fi fi
  
-# check binary+# check binaries
 [[ -f `which mysqldump 2>/​dev/​null` ]] && MYSQLDUMP=mysqldump || print_error "No mysqldump binary found in $PATH" [[ -f `which mysqldump 2>/​dev/​null` ]] && MYSQLDUMP=mysqldump || print_error "No mysqldump binary found in $PATH"
 +[[ -f `which mysql 2>/​dev/​null` ]] && MYSQL=mysql || print_error "No mysql binary found in $PATH"
 +
 +# validate $DB and skip default dbs
 +[[ $DB == all ]] && DB=$(mysql -e 'show databases'​ | tail -n +2 | grep -v -E "​^(information_schema|performance_schema)$"​)
  
 # create dumps # create dumps
 for db in $DB for db in $DB
 do do
 +  # is db exist?
 +  if ! EXISTS=$($MYSQL -s -N -e "show databases"​ | tail -n +2 | grep -x $db)
 +  then
 +    print_info "No such database: $db"
 +    break
 +  fi
 +
   DUMP_FILE=$DUMP_DIR/​$DATE/​$db.sql.gz   DUMP_FILE=$DUMP_DIR/​$DATE/​$db.sql.gz
   # is dump exist?   # is dump exist?
Line 52: Line 64:
     # mkdir     # mkdir
     mkdir -p $DUMP_DIR/​$DATE     mkdir -p $DUMP_DIR/​$DATE
 +
 +    # add --events to mysql db
 +    [[ $db == mysql ]] && OPTS+="​ --events"​
  
     # dump     # dump
Line 70: Line 85:
   done   done
 fi fi
 +
 </​code>​ </​code>​
mysql_backup_simple.txt · Last modified: 2015/04/04 10:39 by kyxap