forked from indigo7333/easy_host_scripts_debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_backup_gp.sh
42 lines (39 loc) · 1.21 KB
/
db_backup_gp.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
41
42
#usage $1=ftp_host $2=folder_name_ftp $3=ftp_pass $4=mysql_pass $5=hourly/daily/monthly $6=pass $7- specific db
lockfile -r 0 /tmp/db_backup_gp.lock || exit 1
ftp_ip=$1
folder_name_ftp=$2
ftp_pass=$3
MYSQL_PASS=$4
FOLDER=$5
SPECIFIC_DB=$7
#DBS=$(`mysql -u root -h localhost --password="$(MYSQL_PASS)" -Bse 'show databases'`)
DBS="$(mysql -u root -h localhost --password="$MYSQL_PASS" -Bse 'show databases')"
for db in $DBS
do
if [ $db = 'information_schema' ] || [ $db = 'phpmyadmin' ] || [ $db = 'performance_schema' ] || [ $db = 'mysql' ]
then
continue
fi
if [ ! -z $SPECIFIC_DB ]
then
if [ $db != $SPECIFIC_DB ]
then
continue
fi
fi
FILE=$db.tar.gz
FOLDER_DB=db_$db
mkdir /tmp/$FOLDER_DB
mysqldump -u root -h localhost --password="$MYSQL_PASS" $db > /tmp/$FOLDER_DB/$db.sql
echo "$(date)" > /tmp/$FOLDER_DB/backup_date.txt
cd /tmp/$FOLDER_DB
tar --exclude='.' -czf /tmp/$FILE *
gpg -o /tmp/$FILE.gpg --passphrase $6 -c /tmp/$FILE
ftp-upload -h $ftp_ip --passive -u ftp_user --password $ftp_pass -d $folder_name_ftp/$FOLDER/mysql/ /tmp/$FILE.gpg
rm /tmp/$FILE
rm /tmp/$FOLDER_DB/$db.sql
rm /tmp/$FOLDER_DB/backup_date.txt
rm /tmp/$FILE.gpg
rmdir /tmp/$FOLDER_DB
done
rm -f /tmp/db_backup_gp.lock