-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestoreClient
More file actions
executable file
·76 lines (60 loc) · 1.35 KB
/
restoreClient
File metadata and controls
executable file
·76 lines (60 loc) · 1.35 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
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
SELF=$(basename $0)
if [ $# -eq 1 ]
then
CLIENT=$1
if ! [ -d /var/cydbackup/$CLIENT ]
then
echo "Cannot find $CLIENT"
exit 1
fi
TAR=$(ls -1tr /var/cydbackup/$CLIENT/$CLIENT*.tgz | tail -1)
elif [ $# -eq 2 ]
CLIENT=$1
if [ -e $2 ]
then
TAR=$2
else
echo "cannot find file $2"
fi
else
echo Usage $SELF client [tar file]
exit 1
fi
check_ret() {
if [ $1 -ne 0 ]
then
echo ERROR $CLIENT
exit 1
fi
}
# Stop the database
sudo systemctl stop odoo_$CLIENT
check_ret $?
# find the last backup
TGZ=$(basename $TAR)
echo $TAR $TGZ
# Copy backup to /tmp
[ -e /tmp/$CLIENT ] || mkdir /tmp/$CLIENT
cp $TAR /tmp/$CLIENT/
cd /tmp/$CLIENT/
# extract the tar
tar zxvf $TGZ
# recreate a fresh db.
dropdb $CLIENT
check_ret $?
createdb $CLIENT
check_ret $?
if [ $(hostname) = "Common" ]
then
sed -i.bak 's/michael/support/' opt/odoo-multi/clients/$CLIENT/$CLIENT.sql
else
sed -i.bak 's/support/michael/' opt/odoo-multi/clients/$CLIENT/$CLIENT.sql
fi
# restore previous db
psql $CLIENT < opt/odoo-multi/clients/$CLIENT/$CLIENT.sql
# refresh client files
[ -d /opt/odoo-multi/clients/$CLIENT ] || mkdir /opt/odoo-multi/clients/$CLIENT
rsync -a opt/odoo-multi/clients/$CLIENT/ /opt/odoo-multi/clients/$CLIENT/ --delete
# restart the db.
sudo systemctl start odoo_$CLIENT