blob: a6d0af5039d8b734ec7f0cb7cadafb5c47f39057 [file] [log] [blame]
Martin Polreich85fa2db2019-02-19 10:29:56 +01001def common = new com.mirantis.mk.Common()
2def salt = new com.mirantis.mk.Salt()
3def galera = new com.mirantis.mk.Galera()
4def python = new com.mirantis.mk.Python()
5def pepperEnv = "pepperEnv"
6
7backupNode = "none"
8primaryNodes = []
9syncedNodes = []
10galeraMembers = []
11
12if (common.validInputParam('OVERRIDE_BACKUP_NODE')) {
13 backupNode = OVERRIDE_BACKUP_NODE
14}
15
16timeout(time: 12, unit: 'HOURS') {
17 node() {
18 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
20 }
21 if (backupNode.equals("none")) {
22 stage('Locate Primary component') {
23 galeraMembers = salt.getMinions(pepperEnv, "I@galera:master or I@galera:slave")
24 for (member in galeraMembers) { // STEP 1 - Locate all nodes that belong to Primary component
25 try {
26 salt.minionsReachable(pepperEnv, "I@salt:master", member)
27 memberStatus = galera.getWsrepParameters(pepperEnv, member, "wsrep_cluster_status", false)
28 if (memberStatus.get('wsrep_cluster_status').equals("Primary")) {
29 primaryNodes.add(member)
30 common.infoMsg("Adding ${member} as a member of a Primary component.")
31 } else {
32 common.warningMsg("Ignoring ${member} node, because it's not part of a Primary component.")
33 }
34 } catch (Exception e) {
35 common.warningMsg("Minion '${member}' is not reachable or is not possible to determine its status.")
36 }
37 }
38 }
39 stage('Choose backup node') {
40 backupNode = primaryNodes.sort()[0] // STEP 2 - Use node with lowest hostname number (last option if everything previous fails)
41 }
42 } else {
43 stage('Choose backup node') {
44 common.infoMsg("Backup node backup was overriden to ${backupNode}.")
45 }
46 }
47 stage ('Prepare for backup') {
48 salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup'])
49 salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client'])
50 }
51 stage('Backup') {
52 common.infoMsg("Node ${backupNode} was selected as a backup node.")
53 input: "Please check selected backup node and confirm to run the backup procedure."
54 salt.cmdRun(pepperEnv, backupNode, "su root -c 'salt-call state.sls xtrabackup'")
55 salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -s'")
56 }
57 stage('Clean-up') {
58 salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -c'")
59 }
60 }
61}