-
Notifications
You must be signed in to change notification settings - Fork 14
/
script.sh
77 lines (61 loc) · 1.34 KB
/
script.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
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
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Linux MySQL Database FTP Backup Script
# Version: 1.0
# Script by: Pietro Marangon
# Skype: pe46dro
# Email: [email protected]
# SFTP function by unixfox and Pe46dro
backup_path="/root"
create_backup() {
umask 177
FILE="$db_name-$d.sql.gz"
mysqldump --user=$user --password=$password --host=$host $db_name | gzip --best > $FILE
echo 'Backup Complete'
}
clean_backup() {
rm -f $backup_path/$FILE
echo 'Local Backup Removed'
}
########################
# Edit Below This Line #
########################
# Database credentials
user="USERNAME HERE"
password="PASSWORD HERE"
host="IP HERE"
db_name="DATABASE NAME HERE"
# FTP Login Data
USERNAME="USERNAME HERE"
PASSWORD="PASSWORD HERE"
SERVER="IP HERE"
PORT="SERVER PORT HERE"
#Remote directory where the backup will be placed
REMOTEDIR="./"
#Transfer type
#1=FTP
#2=SFTP
TYPE=1
##############################
# Don't Edit Below This Line #
##############################
d=$(date --iso)
cd $backup_path
create_backup
if [ $TYPE -eq 1 ]
then
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
binary
cd $REMOTEDIR
mput $FILE
quit
EOF
elif [ $TYPE -eq 2 ]
then
rsync --rsh="sshpass -p $PASSWORD ssh -p $PORT -o StrictHostKeyChecking=no -l $USERNAME" $backup_path/$FILE $SERVER:$REMOTEDIR
else
echo 'Please select a valid type'
fi
echo 'Remote Backup Complete'
clean_backup
#END