forked from indigo7333/easy_host_scripts_debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_backup.sh
27 lines (27 loc) · 949 Bytes
/
db_backup.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
#usage $1=ftp_host $2=folder_name_ftp $3=ftp_pass $4=mysql_pass $5=hourly/daily/monthly
ftp_ip=$1
folder_name_ftp=$2
ftp_pass=$3
MYSQL_PASS=$4
FOLDER=$5
#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
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 *
ftp-upload -h $ftp_ip --passive -u ftp_user --password $ftp_pass -d $folder_name_ftp/$FOLDER/mysql/ /tmp/$FILE
rm /tmp/$FILE
rm /tmp/$FOLDER_DB/$db.sql
rm /tmp/$FOLDER_DB/backup_date.txt
rmdir /tmp/$FOLDER_DB
done