-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollback_demo.sh
More file actions
executable file
·65 lines (52 loc) · 2.02 KB
/
Copy pathrollback_demo.sh
File metadata and controls
executable file
·65 lines (52 loc) · 2.02 KB
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
#!/bin/bash
#****************************************************
# online demo site needs to be regularly cleaned *
# this file will rollback all data contained into *
# backup dir *
#****************************************************
# 1- get the id of the running mongo container
CONTAINER_NAME=$(/usr/local/bin/docker-compose ps | grep mongod | grep -Eo "^([A-Za-z0-9_-]*)")
function restore() {
echo "Restoring backup..."
# 2- restore the backups
cp -R ./backup/mongo/vertest mongoData/
chmod -R a+r mongoData/vertest
docker exec "$CONTAINER_NAME" bash -c "cd /data/db/ && mongorestore -d vertest -c testSuites --drop vertest/testSuites.bson && mongorestore -d vertest -c users --drop vertest/users.bson && mongorestore -d vertest -c metadata --drop vertest/metadata.bson"
# 3- restore the logs
rm -rf ./logs/*
cp -R ./backup/logs/* ./logs/
# 4- restore the git dirs
rm -rf ./cloneDir/*
cp -R ./backup/repos/* ./cloneDir/
# 5- restart the docker containers to refresh all data
/usr/local/bin/docker-compose down
/usr/local/bin/docker-compose -f ./docker-compose.yml up > /dev/null 2>&1 &
}
function backup() {
echo "Creating backup..."
# 2- clean data backup and dump
rm -rf mongoData/vertest
docker exec "$CONTAINER_NAME" bash -c "cd /data/db/ && mongodump -d vertest -c users -o ./ && mongodump -d vertest -c testSuites -o ./ && mongodump -d vertest -c metadata -o ./"
cp -R mongoData/vertest backup/mongo/
# 3- clean logs and copy them from fresh
rm -rf backup/logs/*
cp -R logs/* backup/logs/
# 4- same action with repositories
rm -rf backup/repos/*
cp -R cloneDir/* backup/repos/
}
if [ $1 == "-r" ] ; then
restore
fi
if [ $1 == "-b" ] ; then
backup
fi
if [ $1 == "-h" ] ; then
echo "Script to create or restore backups
options :
-b to create a backup
-r to restore the backup
-h for help
Be aware that in most cases, script have to be ran with root rights
"
fi