forked from aqzt/kjyw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqldump.sh
40 lines (39 loc) · 865 Bytes
/
mysqldump.sh
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
#!/bin/bash
##备份数据库脚本
## http://www.aqzt.com
##email: [email protected]
##robert yu
id="root"
pwd="w@123123"
dbs="aqzhw testdb "
#dbs="aqzhw"
backuppath="/home/mysqldatabak"
day=15
[ ! -d $backpath ] &&mkdir -p $backuppath
cd $backuppath
backupname=$(date +%Y-%m-%d)
for db in $dbs;
do
mysqldump -u$id -p$pwd -S /var/lib/mysql/mysql.sock $db >$backupname_$db.sql
if [ "$?" == "0" ]
then
echo $(date +%Y-%m-%d)" $db mysqldump sucess">>mysql.log
else
echo $(date +%Y-%m-%d)" $db mysql dump failed">>mysql.log
exit 0
fi
done
for db in $dbs;
do
tar -czf $db.$backupname.tar.gz $db.sql
done
if [ "$?" == "0" ]
then
echo $(date +%Y-%m-%d)" tar sucess">>mysql.log
else
echo $(date +%Y-%m-%d)" tar failed">>mysql.log
exit 0
fi
rm -f *.sql
delname=mysql_$(date -d "$day day ago" +%Y-%m-%d).tar.gz
rm -f $delname