Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e178a75

Browse files
authored
Update backup_mysql.sh
MsSQL自动备份 每天晚上23:55自动备份一次 2018年5月23日 添加
1 parent 1d0f03f commit e178a75

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

‎Nginx-Rtmp/backup_mysql.sh‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
#!/bin/bash
22
#######################################################
3-
# $Name: mysql_backup.sh
3+
# $Name: mysql_auto_backup.sh
44
# $Version: v1.0
55
# $Function: Backup MySQL Databases Script
66
# $Author: ShaoBo Wan (Tinywan)
77
# $organization: https://github.com/Tinywan
8-
# $Create Date: 2017年06月29日
9-
# $Description: Mysql 自动备份脚本安全加锁机制
8+
# $Create Date: 2017年06月27日
9+
# $Description: 定期备份MySQL数据库
10+
# $crontab: 55 23 * * * bash $PATH/mysql_auto_backup.sh backup >/dev/null 2>&1
1011
#######################################################
11-
12+
1213
# Shell Env
13-
SHELL_NAME="mysql_backup.sh"
14-
SHELL_TIME=$(date "+%Y-%m-%d")
15-
SHELL_DIR="/home/www/database_back"
16-
SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}-${SHELL_TIME}.log"
14+
SHELL_NAME="mysql_auto_backup.sh"
15+
SHELL_TIME=$(date '+%Y-%m-%d-%H:%M:%S')
16+
SHELL_DAY=$(date '+%Y-%m-%d')
17+
SHELL_DIR="/home/www/data-backup"
18+
SHELL_LOG="${SHELL_DIR}/logs/${SHELL_NAME}-${SHELL_DAY}.log"
1719
LOCK_FILE="/tmp/${SHELL_NAME}.lock"
1820
MYSQL_DUMP="/usr/bin/mysqldump"
19-
MYSQL_BACKUP_DB_NAME="tinywan_mysql"
21+
MYSQL_BACKUP_DB_NAME="resty"
2022
BACKUP_NAME=${MYSQL_BACKUP_DB_NAME}"-${SHELL_TIME}.sql"
21-
23+
2224
# Write Log
2325
loglevel=0 #debug:0; info:1; warn:2; error:3
2426
TIME=`date '+%Y-%m-%d %H:%M:%S'`
2527
shell_log(){
2628
local log_type=1ドル
2729
local LOG_CONTENT=2ドル
30+
# 这里的写入日志时间修改掉,经过一段时间的测试${TIME} 每次都是一个固定的时间,所以在这里修改为每次写入是自动获取当前时间写入日志
2831
logformat="`date '+%Y-%m-%d %H:%M:%S'` \t[${log_type}]\t [${SHELL_NAME}] Function: ${FUNCNAME[@]}\t[line:`caller 0 | awk '{print1ドル}'`]\t [log_info: ${LOG_CONTENT}]"
2932
{
3033
case $log_type in
@@ -39,28 +42,28 @@ shell_log(){
3942
esac
4043
} | tee -a $SHELL_LOG
4144
}
42-
43-
45+
46+
# Shell Usage shell_usage函数,用来告诉用户,这个脚本的使用方法
4447
shell_usage(){
4548
echo $"Usage: 0ドル {backup}"
4649
}
47-
50+
4851
shell_lock(){
4952
touch ${LOCK_FILE}
5053
}
51-
54+
5255
shell_unlock(){
5356
rm -f ${LOCK_FILE}
5457
}
55-
58+
5659
mysql_zip(){
5760
cd $SHELL_DIR
5861
/bin/bzip2 $BACKUP_NAME
59-
find ./ -mindepth 1 -maxdepth 3 -type f -name '*.bz2' -mmin +43200 | xargs rm -rf#进行查找资料,多文件的查找的时候需要增加单引号
60-
find ./ -mindepth 1 -maxdepth 3 -type f -name *.sql -mmin +1440 | xargs rm -rf
61-
find ./ -mindepth 1 -maxdepth 3 -type f -name *.log -mmin +1440 | xargs rm -rf
62+
find ./ -mindepth 1 -maxdepth 3 -type f -name '*.bz2' -mmin +43200 | xargs rm -rf
63+
find ./ -mindepth 1 -maxdepth 3 -type f -name *.sql -mmin +10080 | xargs rm -rf
64+
find ./ -mindepth 1 -maxdepth 3 -type f -name *.log -mmin +10080 | xargs rm -rf
6265
}
63-
66+
6467
# Backup MySQL weblive Database with mysqldump or innobackupex
6568
mysql_backup(){
6669
if [ -f "$LOCK_FILE" ];then
@@ -70,6 +73,7 @@ mysql_backup(){
7073
shell_log info "mysql backup start"
7174
shell_lock
7275
#sleep 10
76+
#$qMYSQL_DUMP $MYSQL_BACKUP_DB_NAME > $SHELL_DIR/$BACKUP_NAME
7377
BACKUP_RES=$($MYSQL_DUMP $MYSQL_BACKUP_DB_NAME > $SHELL_DIR/$BACKUP_NAME && echo "success" || echo "fail")
7478
if [ "${BACKUP_RES}" == "fail" ];then
7579
shell_log error "MYSQL_BACKUP_DB error : ${BACKUP_RES}"
@@ -80,7 +84,7 @@ mysql_backup(){
8084
shell_log info "mysql backup stop"
8185
shell_unlock
8286
}
83-
87+
8488
# Main Function
8589
main(){
8690
case 1ドル in
@@ -90,6 +94,6 @@ main(){
9094
;;
9195
esac
9296
}
93-
97+
9498
#Exec
95-
main 1ドル
99+
main 1ドル

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /