青成林语

协助他人,成就彼此 ^_^
数据库备份小脚本
#!/bin/bash
BACKUP_DIR=/data/backup
USER=root
PASSWD=root
mkdir $BACKUP_DIR
#|| 如果两个操作数中有任意一个非零,则条件为真。 [
-d $BACKUP_DIR ] || mkdir $BACKUP_DIR while true;do cat << EOF please input a number to choice your back up tool: 1.mysqldump 2.xtrabackup 3.quit EOF read -p "Your choose: " choose case "$choose" in 1) mysqldump -u$USER -P$PASSWD -A -F -E -R --single-transaction --master-data=1 --flush-privileges --triggers --default-character-set=utf8 --hex-blob > $BACKUP_DIR/fullback_$(date +%F_%T).sql;; 2) innobackupex --user=$USER --password=$PASSWD $BACKUP_DIR;; 3) echo "Bye!" && exit 2;; *) echo "choose Error !" && exit 3;; esac done

 

posted on 2021-05-14 16:20  青成林语  阅读(52)  评论(0编辑  收藏  举报