-
Notifications
You must be signed in to change notification settings - Fork 20
/
restore.sh
executable file
·83 lines (65 loc) · 2.25 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
#!/bin/bash
# Define basedir
BASEDIR=$(dirname "$0")/../..
# Normalize BASEDIR
CURRENT_DIR=$(pwd)
cd $BASEDIR
BASEDIR=$(pwd)
cd $CURRENT_DIR
BACKUPDIR=$BASEDIR/backup
TEMPDIR=$BACKUPDIR/last-restoration
# Load env variables
export $(grep -v '#.*' $BASEDIR/.env | xargs)
# get archive file
ARCHIVE=$1
if [ "$ARCHIVE" = "" ]; then
echo "Path to archive file is missing"
exit 1
fi
# Recreate a target directory for unpacking
echo -e "Recreating a temp directory for backup data... \c"
rm -rf $TEMPDIR 2>/dev/null
mkdir $TEMPDIR
echo "OK"
# unpack archive
echo -e "Unpacking archive... \c"
tar -xf $ARCHIVE -C $TEMPDIR
echo "OK"
# put files
echo -e "Putting back config files... \c"
# restore .env file
#rm $BASEDIR/.env 2>/dev/null
#cp $TEMPDIR/.env $BASEDIR/ 2>/dev/null
# restore www/.env file
rm $BASEDIR/www/.env 2>/dev/null
cp $TEMPDIR/www/.env $BASEDIR/www/ 2>/dev/null
# restore config files
#rm $BASEDIR/www/application/config/database.php 2>/dev/null
#cp $TEMPDIR/www/application/config/database.php $BASEDIR/www/application/config/ 2>/dev/null
rm $BASEDIR/www/application/config/email.php 2>/dev/null
cp $TEMPDIR/www/application/config/email.php $BASEDIR/www/application/config/ 2>/dev/null
rm $BASEDIR/www/application/config/social.php 2>/dev/null
cp $TEMPDIR/www/application/config/social.php $BASEDIR/www/application/config/ 2>/dev/null
echo "OK"
echo -e "Putting back upload directory... \c"
# get www/upload directory
rm -rf $BASEDIR/www/upload
cp -R $TEMPDIR/upload $BASEDIR/www/
chmod -R 777 $BASEDIR/www/upload
echo "OK"
# restore mysql database
echo "Restoring mysql database..."
docker-compose -f $BASEDIR/docker-compose.yml exec -T mysql /bin/bash -c "mysql -u root --password=$MYSQL_PASSWORD codexmedia" < $TEMPDIR/mysql/codexmedia.sql
# stop redis container
docker-compose -f $BASEDIR/docker-compose.yml stop redis
# import redis db
echo "Restoring redis database..."
rm $BASEDIR/dump/redis/dump.rdb
cp $TEMPDIR/redis/dump.rdb $BASEDIR/dump/redis/
# start redis container
docker-compose -f $BASEDIR/docker-compose.yml start redis
echo "Restarting memcached container..."
# reload memcached container
docker-compose -f $BASEDIR/docker-compose.yml restart memcached
echo ""
echo "Backup $ARCHIVE has been restored successfully"