Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
tingweiwang
/
mysql-backup
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8567a2c0
authored
Nov 07, 2019
by
tingweiwang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql备份脚本
0 parents
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
mysql_backup.sh
mysql_backup.sh
0 → 100755
View file @
8567a2c
#!/bin/bash
# author: wangtingwei
#全备和每个库的备份
#########################################指定多个库单独备份#################################################
HOST
=
"172.24.14.41"
#测试环境数据库
BACK_PATH
=
"/data/mysql_back"
DATE
=
`
date +%F-%H-%M
`
USER
=
"root"
PASSWD
=
"seetatech"
DB_NAME
=(
autodl-core
user-center
seetaas
autocnn
)
#######################################数据库单备##############################################################
single_back
()
{
echo
"创建mysql单库备份所需目录"
test
-d
$BACK_PATH
/
$DATE
-single
||
mkdir
$BACK_PATH
/
$DATE
-single -pv
for
db_name
in
${
DB_NAME
[@]
}
do
mysqldump -u
${
USER
}
-p
${
PASSWD
}
-h
$HOST
--routines --single-transaction --master-data
=
2 -B -F --databases
$db_name
|gzip >
$BACK_PATH
/
$DATE
-single/
$db_name
.sql.gz
done
find
$BACK_PATH
/ -mmin +1 -type d |xargs rm -rf
}
#搭配计划任务,执行频率为1小时1次,只保留一天的备份。
#######################################数据库全备############################################################
all_back
()
{
echo
"创建mysql全库备份所需目录"
test
-d
$BACK_PATH
/
$DATE
-all
||
mkdir
$BACK_PATH
/
$DATE
-all -pv
mysqldump -u
${
USER
}
-p
${
PASSWD
}
-h
$HOST
--routines --single-transaction --master-data
=
2 -A -B -F |gzip >
$BACK_PATH
/
$DATE
-all/all.sql.gz
find
$BACK_PATH
/ -mmin +1 -type d |xargs rm -rf
}
#搭配计划任务,执行频率为1天1次,只保留一天的备份。
###################################################################################################
case
$1
in
single_back
)
single_back
;;
all_back
)
all_back
;;
*
)
echo
"please input (single_back|all_back)"
esac
#################################################添加计划任务如下##############################
#* */1 * * * root sh /root/common-script/mysql_backup.sh single_back #单库备份频率,每小时一次
#12 12 * * * root sh /root/common-script/mysql_backup.sh all_back #全库备份频率,每天一次。
###################################数据恢复操作########################################################
#gunzip < /path/xxxx.sql.gz | mysql -uroot -proot databasename 单库
#gunzip < /path/xxxx.sql.gz | mysql -uroot -proot 全库
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment