-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
executable file
·150 lines (118 loc) · 3.22 KB
/
restore.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
ARGF=$1
ARGDB=$2
NOW=$(date +"%Y-%m-%d-%H%M")
clear
echo -e "\n********* RESTORE TOOL BY DANIELE CRUPI *********\n"
#se è automatizzato in cron
if [ $ARGDB ]; then
while true
do
case $ARGDB in
0)
break
;;
*)
echo -e "\n"
echo $ARGF
echo -e "sto eseguendo il ripristino del database..........."
mysql -uroot -proot -h localhost $ARGDB | gzip -9c < $ARGF
echo -e "fatto\n"
break
;;
esac
done
else
#backup db
echo -n "Vuoi fare il ripristino del database? [Y/n]"
read bkdb || exit 1
case "$bkdb" in
[Nn]*) bkdb=n with=out;;
*) bkdb=y with=;;
esac
if [ 'y' = $bkdb ]; then
echo -e "Mi servono gli accessi al database\n"
echo -n "Inserisci il nome del server host [ENTER]: "
read HOST
echo -n "Inserisci lo username [ENTER]: "
read DBUSER
echo -n "Inserisci la password [ENTER]: "
read DBPSW
echo -n "Inserisci il nome del database [ENTER] (Y - view list): "
read DBNAME || exit 1
case "$DBNAME" in
[Nn]*) DBNAME =n with=out;;
*) DBNAME =y with=;;
esac
if [ 'y' = $DBNAME ]; then
echo "SHOW DATABASES;" | mysql -u$DBUSER -p$DBPSW -h $HOST
echo -n "Inserisci il nome del database [ENTER]: "
read DBNAME
echo -e "\n"
echo $ARGF
echo -e "sto eseguendo il ripristino del database..........."
mysql -u$DBUSER -p$DBPSW -h $HOST $DBNAME | gzip -9c < $ARGF
echo -e "fatto\n"
else
echo -e "\n"
echo $ARGF
echo -e "sto eseguendo il ripristino del database..........."
mysql -u$DBUSER -p$DBPSW -h $HOST $DBNAME | gzip -9c < $ARGF
echo -e "fatto\n"
fi
fi
fi
#se è automatizzato in cron
if [ $ARGDB ]; then
if [ -d "$ARGDB" ]; then
#ARGDB="${ARGDB////}"
echo "estraggo '$ARGF' in '$ARGDB'"
echo -n "sto eseguendo il ripristino dei files..........."
tar -xvf $ARGF -C $ARGDB
echo -e "fatto\n"
else
echo -e "cartella '$ARGDB' non esistente!\n"
fi
else
#backup files
echo -n "Vuoi fare il ripristino dei files? [Y/n]"
read bkfiles || exit 1
case "$bkfiles" in
[Nn]*) bkfiles=n with=out;;
*) bkfiles=y with=;;
esac
if [ 'y' = $bkfiles ]; then
echo -n "Inserisci il nome della cartella dove vuoi fare il ripristino: [ENTER] (Y - view list): "
read directory || exit 1
case "$directory" in
[Nn]*) directory =n with=out;;
*) directory =y with=;;
esac
if [ 'y' = $directory ]; then
echo | ls
echo -n "Inserisci il nome della cartella dove vuoi fare il ripristino: [ENTER]: "
read directory
echo -e "\n"
#directory="${directory////}"
if [ -d "$directory" ]; then
echo "estraggo '$ARGF' in '$directory'"
echo -n "sto eseguendo il ripristino dei files..........."
tar -xvf $ARGF -C $directory
echo -e "fatto\n"
else
echo -e "cartella '$directory' non esistente!\n"
fi
else
#directory="${directory////}"
if [ -d "$directory" ]; then
echo "estraggo '$ARGF' in '$directory'"
echo -n "sto eseguendo il ripristino dei files..........."
tar -xvf $ARGF -C $directory
echo -e "fatto\n"
else
echo -e "cartella '$directory' non esistente!\n"
fi
fi
fi
fi
echo -e "\n********************* END *************************\n"