blob: 345f280cfd0c94c7dd953fa8173d95ee81e50f30 [file] [log] [blame]
Jiri Broulik7e90fec2017-06-02 10:18:17 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
7 *
8**/
9
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
12
13
14def saltMaster
15
16timestamps {
17 node() {
18
19 stage('Connect to Salt API') {
20 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
21 }
22
23 stage('Start restore') {
24 // # actual upgrade
25
26 stage('Ask for manual confirmation') {
27 input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore mysql db?"
28 }
29 // database restore section
30 try {
31 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
32 } catch (Exception er) {
33 common.warningMsg('Mysql service already stopped')
34 }
35 try {
36 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
37 } catch (Exception er) {
38 common.warningMsg('Mysql service already stopped')
39 }
40 try {
41 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
42 } catch (Exception er) {
43 common.warningMsg('Files are not present')
44 }
45 try {
Jiri Broulik1c513982017-07-04 22:19:51 +020046 salt.cmdRun(saltMaster, 'I@galera:master', "mkdir -p /root/mysql/mysql.bak")
Jiri Broulik7e90fec2017-06-02 10:18:17 +020047 } catch (Exception er) {
48 common.warningMsg('Directory already exists')
49 }
50 try {
Jiri Broulik7e90fec2017-06-02 10:18:17 +020051 salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
52 } catch (Exception er) {
53 common.warningMsg('Files were already moved')
54 }
55 try {
Jiri Broulik1c513982017-07-04 22:19:51 +020056 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*")
57 } catch (Exception er) {
58 common.warningMsg('Directory already empty')
59 }
60 try {
Jiri Broulik7e90fec2017-06-02 10:18:17 +020061 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
62 } catch (Exception er) {
63 common.warningMsg('File is not present')
64 }
65 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
66 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
67 backup_dir = _pillar['return'][0].values()[0]
68 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
69 print(backup_dir)
70 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
71 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
72 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020073
74 // wait until mysql service on galera master is up
75 salt.commandStatus(saltMaster, 'I@galera:master', 'service mysql status', 'running')
76
Jiri Broulik7e90fec2017-06-02 10:18:17 +020077 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
78 sleep(15)
79 salt.cmdRun(saltMaster, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'")
80
81 }
82 }
83}
84
85
86