备份脚本1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# **********************************************************
# * Author : liujinxin
# * Email : liuJinXin0726@outlook.com
# * Create time : 2021-05-10 22:12
# * Filename : openvpnCentos8.sh
# * Description :
# **********************************************************
PATH=/app/cmatrix/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
. /etc/init.d/functions
TIME=`date +%F`
INCTIME=`date -d -1day`
NAME=`$HOSTNAME`
DIRDATA=/data/backup
DB=hellodb
PASSWD=

backup_mysqlDB(){
[ -d $DIRDATA ] '' mkdir $DIRDATA
mysqldump -uroot -p"$PASSWD" -F -A --single-transaction --master-data=1 ' gzip >$DIRDATA_Backup_$TIME.sql.zip
action "$DIRDATA_Backup_$TIME.sql.zip 备份成功"
}

backup_mysqlDB_Sub-library(){
[ -d $DIRDATA ] '' mkdir $DIRDATA
mysqldump -uroot -p"$PASSWD" -F -E -R --single-transaction --master-data=1 --default-character-set=uft8 -q -B $DB' gzip >$DIRDATA_Backup_$DB_$TIME.sql.zip
action "$DIRDATA_Backup_$DB_$TIME.sql.zip 备份成功"
}

#增量备份
backup_mysqlDB_Increment(){

rpm -qi wget ' yum install wget -y
package=Percona-XtraDB-Cluster-server-57-5.7.33-31.49.1.el7.x86_64.rpm
yum install -y $package
[ -d $DIRDATA ] ' mkdir $DIRDATA
complete(){
xtrabackup -uroot -p"$PASSWD" --backup --target-dir=$DIRDATA/$NAME_$TIME #完全备份
}
one_inc(){
xtrabackup -uroot -p"$PASSWD" --backup --target-dir=$DIRDATA/$NAME_Increment_$TIME --increment-basedir=$DIRDATA/$NAME_$INCTIME
}
two_inc(){
xtrabackup -uroot -p"$PASSWD" --backup --target-dir=DIRDATA/$NAME_Increment_$TIME --increment-basedir=$DIRDATA/$NAME_Increment_$INCTIME
}

}
PS3="请输入需要备份的菜单(1-5):"
select NEMU in 完全备份 分库备份 增量备份;do
case $REPLY in
1)
backup_mysqlDB
;;
2)

backup_mysqlDB_Sub-library
;;
3)
backup_mysqlDB_Increment
;;
4)
function_openvpn.remove
;;
*)
echo "Please enter the correct parameters (0-6) "
esac
done

备份脚本2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
#
#********************************************************************
#Author: Mr.yang
#QQ: 1419946323
#Date: 2021-06-22
#FileName: mysq_backup.sh
#URL: www.yhtzjy.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
TIME=`date +%F_%H-%M-%S`
DIR=/backup
DB=hellodb
PASS=magedu
[ -d $DIR ] '' mkdir $DIR
mysqldump -uroot -p "$PASS" -F -E -R --triggers --single-transaction --master-data=2 --default-character-set=utf8 -q -B $DB ' gzip > ${DIR}/${DB}_${TIME}.sql.gz

#生产中略有不同只供参考
chmod +x mysql_backup.sh
#生产建议添加计划任务脚本
crontable -e
* * * * * /root/mysql_backup.sh

#执行成功后我们可以解开查看是否可以还原,生产中可以拷贝到新的数据库测试
set sql_log_bin=0; #先关闭二进制日志
souce /backup/*
#后续在启用二进制日志
set sql_logbin=1;