-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrestore.sh
62 lines (47 loc) · 863 Bytes
/
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
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Missing argument"
exit 1
fi
BACKUP_FILE=$1
WD=$(dirname "$(realpath $BASH_SOURCE)")
if [ ! -e $BACKUP_FILE ]
then
echo "The given file doesn't exist"
exit 1
fi
echo "Backup file: $BACKUP_FILE"
if [ ! -d "$WD/temp" ]
then
mkdir "$WD/temp"
if [ $? -eq 0 ]
then
echo "$WD/temp folder create"
else
echo "Error during the creation of the folder $WD/temp"
exit 1
fi
fi
echo "Unzipping file..."
unzip -q $BACKUP_FILE -d "$WD/temp"
if [ $? -ne 0 ]
then
echo "Error during the creation of the zip file"
exit 1
fi
echo "Unzip end"
echo "Restoring folder"
FOLDERS_TO_RESTORE=$(ls "$WD/temp")
for folder in $FOLDERS_TO_RESTORE
do
echo " - $folder to $WD/$folder"
if [ -d "$WD/$folder" ]
then
rm -r "$WD/$folder"
fi
cp -r "$WD/temp/$folder" "$WD/$folder"
done
rm -r "$WD/temp"
echo "Done"
exit 0