Martin Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def salt = new com.mirantis.mk.Salt() |
| 3 | def galera = new com.mirantis.mk.Galera() |
| 4 | def python = new com.mirantis.mk.Python() |
| 5 | def pepperEnv = "pepperEnv" |
| 6 | |
| 7 | backupNode = "none" |
| 8 | primaryNodes = [] |
| 9 | syncedNodes = [] |
| 10 | galeraMembers = [] |
| 11 | |
| 12 | if (common.validInputParam('OVERRIDE_BACKUP_NODE')) { |
| 13 | backupNode = OVERRIDE_BACKUP_NODE |
| 14 | } |
| 15 | |
| 16 | timeout(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 Polreich | aceda37 | 2019-08-23 15:55:25 +0200 | [diff] [blame] | 60 | stage('Backup Dogtag') { |
Martin Polreich | 520781e | 2019-09-23 18:08:32 +0200 | [diff] [blame] | 61 | if (!salt.getMinions(pepperEnv, "I@dogtag:server:enabled").isEmpty()) { |
| 62 | dogtagBackupBuild = build(job: 'backupninja_backup', parameters: [ |
Martin Polreich | aceda37 | 2019-08-23 15:55:25 +0200 | [diff] [blame] | 63 | [$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 Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 74 | } |
| 75 | } |