forked from todiadiyatmo/bash-backup-rotation-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·56 lines (46 loc) · 2.01 KB
/
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
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
#!/bin/bash
# Configuration Filename
CONF="backup.conf"
# Script Filename
SCRIPT="backup_rotation.sh"
# Do not edit below this line
CONF=${PWD}/$CONF
SCRIPT=${PWD}/$SCRIPT
DATETIME=`date '+%Y%m%d'`
umask 066
exec < $CONF
while read line
do
if [ -n "$line" ]
then
if [ ${line:0:1} != '#' ]
then
TYPE=`echo $line | awk '{print $1}'`
HOST=`echo $line | awk '{print $2}'`
SQLFR=`echo $line | awk '{print $3}'`
DATABASE=`echo $line | awk '{print $4}'`
USER=`echo $line | awk '{print $5}'`
PASSWORD=`echo $line | awk '{print $6}'`
FILES_FR=`echo $line | awk '{print $7}'`
DIRECTORY=`echo $line | awk '{print $8}'`
DEST_BASE_DIR=`echo $line | awk '{print $9}'`
DEST_DIR="$DEST_BASE_DIR/$HOST/$DATABASE"
if [ ! -e "$DIRECTORY" ]; then
mkdir "$DIRECTORY"
fi
if [ ! -e "$DEST_DIR" ]; then
mkdir "$DEST_DIR"
fi
if [ "$TYPE" == 'local' ]; then
$SCRIPT --sql "$SQLFR" $HOST $USER $PASSWORD $DATABASE --backupdir "$FILES_FR" $DIRECTORY --targetdir "$DEST_DIR"
fi
if [ "$TYPE" == 'ftp' ]; then
FTP_HOST=`echo $line | awk '{print $10}'`
FTP_PORT=`echo $line | awk '{print $11}'`
FTP_USER=`echo $line | awk '{print $12}'`
FTP_PASSWORD=`echo $line | awk '{print $13}'`
$SCRIPT --sql "$SQLFR" $HOST $USER $PASSWORD $DATABASE --backupdir "$FILES_FR" $DIRECTORY --ftp "$FTP_HOST" "$FTP_PORT" "$FTP_USER" "$FTP_PASSWORD" "$DEST_DIR"
fi
fi
fi
done