-
Notifications
You must be signed in to change notification settings - Fork 5
/
init_mirror.sh
executable file
·80 lines (70 loc) · 2.29 KB
/
init_mirror.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
#!/bin/bash
nohup $IRISSYS/ISCAgentUser start &>/dev/null &
sleep 1
MIRROR_NAME=Demo
DATABASE=/opt/demo/data
BACKUP_FOLDER=/opt/backup
make_backup() {
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(SYS.Database).DismountDatabase(\"${DATABASE}\")"
# iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(Backup.General).ExternalFreeze()"
md5sum ${DATABASE}/IRIS.DAT
cp ${DATABASE}/IRIS.DAT ${BACKUP_FOLDER}/IRIS.DAT
# iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(Backup.General).ExternalThaw()"
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(SYS.Database).MountDatabase(\"${DATABASE}\")"
return 0
}
# Enable Mirroring
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS <<- END
do ##class(Security.Services).Get("%Service_Mirror", .svcProps)
set svcProps("Enabled") = 1
do ##class(Security.Services).Modify("%Service_Mirror", .svcProps)
halt
END
exit=$?
if [ $exit -ne 0 ];
then
exit $exit;
fi
master() {
rm -rf $BACKUP_FOLDER/IRIS.DAT
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS <<- END
set mirror("UseSSL") = 0
set mirror("ArbiterNode") = "$1|2188"
set sc = ##class(SYS.Mirror).CreateNewMirrorSet("${MIRROR_NAME}", "master", .mirror)
if 'sc do \$system.OBJ.DisplayError(sc) quit
hang 2
set sc = ##class(SYS.Mirror).AddDatabase("${DATABASE}", "DEMO-DATA")
if 'sc do \$system.OBJ.DisplayError(sc)
hang 2
halt
END
}
restore_backup() {
sleep 5
while [ ! -f $BACKUP_FOLDER/IRIS.DAT ]; do sleep 1; done
sleep 2
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(SYS.Database).DismountDatabase(\"${DATABASE}\")"
cp $BACKUP_FOLDER/IRIS.DAT $DATABASE/IRIS.DAT
md5sum $DATABASE/IRIS.DAT
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS "##class(SYS.Database).MountDatabase(\"${DATABASE}\")"
}
backup() {
iris session $ISC_PACKAGE_INSTANCENAME -U %SYS <<- END
set sc = ##class(SYS.Mirror).JoinMirrorAsFailoverMember("${MIRROR_NAME}", "backup", "${ISC_PACKAGE_INSTANCENAME}", "$1")
if 'sc do \$system.OBJ.DisplayError(sc)
hang 2
set sc = ##class(SYS.Mirror).ActivateMirroredDatabase("${DATABASE}")
if 'sc do \$system.OBJ.DisplayError(sc)
hang 2
set sc = ##class(SYS.Mirror).CatchupDB(\$lb(+\$zu(49, "${DATABASE}")))
if 'sc do \$system.OBJ.DisplayError(sc)
halt
END
}
if [ "$IRIS_MIRROR_ROLE" == "master" ]; then
master $IRIS_MIRROR_ARBITER
make_backup
else
restore_backup
backup $IRIS_MIRROR_AGENT
fi