blob: 466c7eadbae7701297f17aa082c84bb9531452d9 [file] [log] [blame]
Martin Polreich9c4a84d2019-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 = []
Valeriy Sakharov9a7295a2021-05-31 13:09:34 +040011maxValue = 0
12masterNode = "none"
Martin Polreich9c4a84d2019-02-19 10:29:56 +010013
14if (common.validInputParam('OVERRIDE_BACKUP_NODE')) {
15 backupNode = OVERRIDE_BACKUP_NODE
16}
17
18timeout(time: 12, unit: 'HOURS') {
19 node() {
20 stage('Setup virtualenv for Pepper') {
21 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
22 }
23 if (backupNode.equals("none")) {
24 stage('Locate Primary component') {
25 galeraMembers = salt.getMinions(pepperEnv, "I@galera:master or I@galera:slave")
26 for (member in galeraMembers) { // STEP 1 - Locate all nodes that belong to Primary component
27 try {
28 salt.minionsReachable(pepperEnv, "I@salt:master", member)
29 memberStatus = galera.getWsrepParameters(pepperEnv, member, "wsrep_cluster_status", false)
30 if (memberStatus.get('wsrep_cluster_status').equals("Primary")) {
31 primaryNodes.add(member)
32 common.infoMsg("Adding ${member} as a member of a Primary component.")
33 } else {
34 common.warningMsg("Ignoring ${member} node, because it's not part of a Primary component.")
35 }
36 } catch (Exception e) {
37 common.warningMsg("Minion '${member}' is not reachable or is not possible to determine its status.")
38 }
39 }
40 }
41 stage('Choose backup node') {
Valeriy Sakharov9a7295a2021-05-31 13:09:34 +040042 primaryNodes = primaryNodes.sort()
43 for (node in primaryNodes.reverse()) { // Looking for the node with the highest mysql_queries value
44 try {
45 queriesValue = galera.getWsrepParameters(pepperEnv, node, "Queries", false).get('Queries')
46 common.infoMsg("Queries for ${node} - ${queriesValue}")
47 if (queriesValue >= maxValue) {
48 maxValue = queriesValue
49 masterNode = node
50 common.infoMsg("Current main node in galera cluster: ${masterNode}")
51 }
52 } catch (Exception e) {
53 common.warningMsg("Minion '${node}' unavailable.")
54 }
55 }
56 if (masterNode.equals("none")) {
57 backupNode = primaryNodes[-1] // STEP 2 - Use node with highest hostname number (last option if everything previous fails)
58 } else {
59 common.infoMsg("Master node is ${masterNode}.")
60 primaryNodes = primaryNodes.minus(masterNode)
61 backupNode = primaryNodes[-1]
62 }
63 common.infoMsg("Choose backup node as ${backupNode}.")
64 }
Martin Polreich9c4a84d2019-02-19 10:29:56 +010065 } else {
66 stage('Choose backup node') {
67 common.infoMsg("Backup node backup was overriden to ${backupNode}.")
68 }
69 }
70 stage ('Prepare for backup') {
71 salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup'])
72 salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client'])
73 }
74 stage('Backup') {
75 common.infoMsg("Node ${backupNode} was selected as a backup node.")
76 input: "Please check selected backup node and confirm to run the backup procedure."
77 salt.cmdRun(pepperEnv, backupNode, "su root -c 'salt-call state.sls xtrabackup'")
78 salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -s'")
79 }
80 stage('Clean-up') {
81 salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -c'")
82 }
Martin Polreich87fe5cd2019-08-23 15:55:25 +020083 stage('Backup Dogtag') {
Martin Polreich19d98e62019-09-23 18:08:32 +020084 if (!salt.getMinions(pepperEnv, "I@dogtag:server:enabled").isEmpty()) {
85 dogtagBackupBuild = build(job: 'backupninja_backup', parameters: [
Martin Polreich87fe5cd2019-08-23 15:55:25 +020086 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL],
87 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
88 [$class: 'BooleanParameterValue', name: 'ASK_CONFIRMATION', value: "false"],
89 [$class: 'BooleanParameterValue', name: 'BACKUP_SALTMASTER_AND_MAAS', value: "false"],
90 [$class: 'BooleanParameterValue', name: 'BACKUP_DOGTAG', value: "true"],
91 ]
92 )
93 } else {
94 common.warningMsg("Dogtag pillar not found. This is fine if you are using different Barbican backend.")
95 }
96 }
Martin Polreich9c4a84d2019-02-19 10:29:56 +010097 }
Valeriy Sakharov9a7295a2021-05-31 13:09:34 +040098}