-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mysql自动备份部署.txt
42 lines (32 loc) · 1.3 KB
/
Mysql自动备份部署.txt
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
MySQL用户与密码:
账号就是:root
密码:hdzxzj!qazxsw2
Linux操作:
]#cd /srv ;mkdir -p bak_database/bak
]#vim /srv/bak_database/mysql_bak.sh
#!/bin/bash
#===========================================================================
# FileName: mysql_bak.sh
#
# Author : WangXinKun
#
# Created : 12:00,23/03/2020
#===========================================================================
# Backup file is saved in the directory, if it does not exist Create
basepath='/srv/bak_database/bak/'
if [ ! -d "$basepath" ]; then
mkdir -p "$basepath"
fi
# mysql bakcup to /srv/bak_database/bak/
date_now=`date +"%Y-%m-%d-%H_%M_%S"`
/srv/program/mysql/mysql-5.7/bin/mysqldump --log-error=bak/xczwzn-$date_now-error.log --single-transaction -h 127.0.0.1 -P 3307 --set-gtid-purged=OFF -u root -p'hdzxzj!qazxsw2' xczwzn |gzip > bak/xczwzn-$date_now.sql.gz
# Delete the backup data to 30 days before
#find $basepath -mtime 30 -name "*.sql.gz" -exec rm -rf {} \;
find $basepath -mtime 30 -name "*.sql.gz" -exec rm -rf {} \; -or -mtime 30 -name "*-error.log" -exec rm -rf {} \;
:wq
]#/etc/init.d/crond status
]#systemctl start crond
]#systemctl enable crond
]#crontab -e -u root
01 01 * * * cd /srv/bak_database;./mysql_bak.sh
]#crontab -l -u root