forked from esimonetti/SugarDockerized
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrestore.sh
executable file
·112 lines (93 loc) · 3.47 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
#!/bin/bash
# Enrico Simonetti
# enricosimonetti.com
if [ -z $1 ]
then
echo Provide the backup suffix as script parameters
else
# check if the stack is running
running=`docker ps | grep sugar-mysql | wc -l`
# check if rsync is installed
if [ `command -v rsync | grep rsync | wc -l` -eq 0 ]
then
echo Please install \"rsync\" before running the restore command
exit 1
fi
if [ $running -gt 0 ]
then
# running
# enter the repo's root directory
REPO="$( dirname ${BASH_SOURCE[0]} )/../"
cd $REPO
BACKUP_DIR="backups/backup_$1"
# check if the backup name has been provided including the backup_ prefix
if [ ! -d $BACKUP_DIR ] && [ -d "backups/$1" ]
then
BACKUP_DIR="backups/$1"
fi
echo Restoring sugar from \"$BACKUP_DIR\"
# if it is our repo, and the source exists, and the destination does not
if [ -f '.gitignore' ] && [ -d 'data' ] && [ -d $BACKUP_DIR ] && [ -d $BACKUP_DIR/sugar ] && ( [ -f $BACKUP_DIR/sugar.sql ] || [ -f $BACKUP_DIR/sugar.sql.tgz ] )
then
if [ -d 'data/app/sugar' ]
then
rm -rf data/app/sugar
fi
echo Restoring application files
sudo rsync -a $BACKUP_DIR/sugar data/app/
echo Application files restored
echo Restoring database
docker exec -it sugar-mysql mysqladmin -h localhost -f -u root -proot drop sugar | grep -v "mysqladmin: \[Warning\]"
docker exec -it sugar-mysql mysqladmin -h localhost -u root -proot create sugar | grep -v "mysqladmin: \[Warning\]"
if [ -f $BACKUP_DIR/sugar.sql.tgz ]
then
if hash tar 2>/dev/null; then
tar -zxf $BACKUP_DIR/sugar.sql.tgz
echo Database uncompressed to $BACKUP_DIR/sugar.sql
fi
fi
if [ -f $BACKUP_DIR/sugar.sql ]
then
cat $BACKUP_DIR/sugar.sql | docker exec -i sugar-mysql mysql -h localhost -u root -proot sugar
echo Database restored
else
echo Database not found! The selected restore is corrupted
exit 1
fi
if [ -f $BACKUP_DIR/sugar.sql.tgz ]
then
if [ -f $BACKUP_DIR/sugar.sql ]
then
rm $BACKUP_DIR/sugar.sql
fi
fi
# refresh all transient storages
./utilities/build/refreshsystem.sh
echo Repairing system
./utilities/repair.sh
echo System repaired
echo Performing Elasticsearch re-index
./utilities/runcli.sh "./bin/sugarcrm search:silent_reindex"
echo Restore completed!
else
if [ ! -d 'data' ]
then
echo \"data\" cannot be empty, the command needs to be executed from within the clone of the repository
fi
if [ ! -d $BACKUP_DIR/sugar ]
then
echo \"$BACKUP_DIR/sugar\" cannot be empty
fi
if [ ! -f $BACKUP_DIR/sugar.sql ]
then
echo \"$BACKUP_DIR/sugar.sql\" does not exist
fi
if [ ! -d $BACKUP_DIR ]
then
echo $BACKUP_DIR does not exist
fi
fi
else
echo The stack is not running, please start the stack first
fi
fi