blob: 8239aa672c2a22a77672d56d6c621e33287fef76 [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 }
Martin Polreichaceda372019-08-23 15:55:25 +020060 stage('Backup Dogtag') {
Martin Polreich520781e2019-09-23 18:08:32 +020061 if (!salt.getMinions(pepperEnv, "I@dogtag:server:enabled").isEmpty()) {
62 dogtagBackupBuild = build(job: 'backupninja_backup', parameters: [
Martin Polreichaceda372019-08-23 15:55:25 +020063 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL],
64 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
65 [$class: 'BooleanParameterValue', name: 'ASK_CONFIRMATION', value: "false"],
66 [$class: 'BooleanParameterValue', name: 'BACKUP_SALTMASTER_AND_MAAS', value: "false"],
67 [$class: 'BooleanParameterValue', name: 'BACKUP_DOGTAG', value: "true"],
68 ]
69 )
70 } else {
71 common.warningMsg("Dogtag pillar not found. This is fine if you are using different Barbican backend.")
72 }
73 }
Martin Polreich85fa2db2019-02-19 10:29:56 +010074 }
75}