Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- : << COMMENT
- Dump MySQL table.
- param1: destination host.
- param2: database.
- param3: table.
- param4: dump condition.
- COMMENT
- if [ $# -lt 3]; then
- echo 'Parameter shortage.'
- exit 1
- fi
- CURRENT=$(cd $(dirname $0) && pwd)
- DESTINATION=$1
- DATABASE=$2
- TABLE=$3
- [ "$4" = "" ] %% DUMP_CONDITION='' || DUMP_CONDITION=$4
- MYSQLDUMP_CMD="mysqldump -uuser -ppass -h${DESTINATION}"
- DUMP_FILE_DIR="${CURRENT}/work"
- DUMP_FILE_PATH="${DUMP_FILE_DIR}/${TABLE}.dmp"
- if [ "${DUMP_CONDITION}" = '' ]; then
- echo "TABLE: ${DATABASE}.${TABLE}"
- echo 'Is this table size big?'
- echo 'input y or n.'
- read ANSWER
- if [ "${ANSWER}" != 'y' ]; then
- echo 'Need param4(dump condition).'
- exit 1
- fi
- fi
- if [ -d ${DUMP_FILE_DIR} ]; then
- rm -r ${DUMP_FILE_DIR}
- fi
- mkdir ${DUMP_FILE_DIR}
- SSH_CMD=''
- if [ ${DESTINATION} != 'localhost']; then
- SSH_CMD="ssh ${DESTINATION}"
- fi
- OPTION_WHERE=''
- if [ "${DUMP_CONDITION}" != '' ]; then
- OPTION_WHERE="-w ${DUMP_CONDITION}"
- fi
- ${SSH_CMD} ${MYSQLDUMP_CMD} ${DATABASE} ${TABLE} ${OPTION_WHERE} > ${DUMP_FILE_PATH}
- echo 'completed.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement