Operation methods of manual backup and automatic backup of mysql
Next, let's learn about the operation of manual backup and automatic backup of mysql. I believe you will benefit a lot after reading it. The text is not much in essence. I hope this short article of manual backup and automatic backup of mysql is what you want.
/ # #! / bin/bash
/ #
/ # # DATE: 2019-10-22 #
/ # # AUTHOR: zhangy_j #
/ # # FUNC: determine the specified database name, and exit the program if not specified #
/ # # backup the specified database according to the current test test database #
/ # # this script can be run alone or automatically called at 11:00 and 23:00 every day
/ #
/ # #-|-#
/ #
/ # # two kinds of backups, automatic backup and manual backup in crontab
/ # # by default, the database in the datafile.db file is backed up and retained for 30 days.
/ # # Manual backup method, dbbak database name, for example: dbbak 11111. Files backed up manually are retained for 7 days.
# Import method: mysql-uroot-pxxx gp-manage1 / dev/null 2 > & 1
/ # export BAK=/tmp/yujun > / dev/null 2 > & 1
/ # chmod 755-R $BAK
/ # DATAFILE=$ {BAK} / datafile.db
/ # DATA_DIR=$ {BAK}
/ # BAK_DIR=$ {BAK} / bak
/ # BAK_DT=date +% Y%m%d
/ # BAK_LOG=$ {BAK_DIR} / databak$ {BAK_DT} _ log
/ # FILE_DT=dbdate +% H
/ # DB_USER='root'
/ # # Backup database host
/ # DB_HOST= "10.1.1.10"
/ # Dempster 1
/ #
/ #
/ # if [x "$1"! = x]; then
/ # # read-p "Please enter the name of the database to be backed up on the ${DB_HOST} host:" D
/ # # read-p "Please enter the user name in the ${DB_HOST} host:" U
/ # # read-p "Please enter the user password in the ${DB_HOST} host:" P
/ #
/ #
/ #
/ # echo "- [date" +% Y/%m/%d% H:%M:%S "] start backing up $U database -"
/ # mysqldump-opt-single-transaction-master-data=2-u$DB_USER-p$pass\
/ #-h$DB_HOST ${D} > ${PWD} / ${D} .sql
/ # echo "- [date" +% Y/%m/%d% H:%M:%S "] backup completed $U database -"
/ #
/ #
/ # else
/ #
/ # Database backup user
/ # DB_USER='root'
/ #
/ #
/ #
/ #
/ #
/ # # Create backup directory
/ # if [!-d ${BAK_DIR} / ${BAK_DT}]; then
/ # mkdir-p ${BAK_DIR} / ${BAK_DT} > / dev/null
/ # fi
/ #
/ # if [!-f ${DATAFILE}]
/ # then
/ # echo "$DATAFILE file does not exist!"
/ # echo "Please enter all the database names to be backed up in $DATAFILE!"
/ #
/ #
/ # exit
/ # fi
/ #
/ # print_log () {
/ # MYDATE=date + "Y-%m-%d H:%M:%S"
/ # case ${2} in
/ # 1)
/ # printf "%-40s%s\ n"$1" $3 $4 $5 $6 $7 $8 ${9} "
/ # printf "%-40s%s\ n" $1 "$3 $4 $5 $6 $7 $8 ${9}" > ${BAK_LOG}
/ #
/ # *)
/ # echo "input error" > > ${BAK_LOG}
/ #
/ # esac
/ #}
/ #
/ # cd ${BAK_DIR} | | exit
/ #
/ # # read-p "Please enter the database you want to back up:" DB
/ #
/ #
/ # for i in cat $DATA_DIR/datafile.db
/ # do
/ # print_log "The database to be backed up is named: $I"1"
/ #
/ # DB_FILE=$ {FILEDT} $i.sql
/ #
/ # echo "- [date" +% Y/%m/%d% H:%M:%S "] start backup ${I}\
/ # Database-"> > ${BAK_LOG}
/ # mysqldump-opt-single-transaction-master-data=2-u$DB_USER\
/ #-p$pass-h$DB_HOST ${I} > ${BAK_DIR} / ${BAK_DT} / ${DB_FILE}
/ # echo "- [date" +% Y/%m/%d% H:%M:%S "] backup completes ${I} database,\
/ # backup file ${DB_FILE}-"> > ${BAK_LOG}
/ # done
/ #
/ # fi
After reading this article on manual backup and automatic backup of mysql, many readers will want to know more about it. If you need more industry information, you can follow our industry information section.