annotate modules/mysql/tasks/export.rb @ 482:d83de9b3a62b default tip

Update hiera.yaml within Puppet config Forgot that we manage it from here. Now has content to match new packages
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Aug 2024 16:10:36 +0100
parents adf6fe9bbc17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #!/opt/puppetlabs/puppet/bin/ruby
389
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
2 # frozen_string_literal: true
668df4711671 Update MySQL modules
IBBoard <dev@ibboard.co.uk>
parents: 244
diff changeset
3
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 require 'json'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 require 'open3'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 require 'puppet'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 def get(file, database, user, password)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 cmd_string = 'mysqldump'
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 cmd_string << " --databases #{database}" unless database.nil?
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 cmd_string << " --user=#{user}" unless user.nil?
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 cmd_string << " --password=#{password}" unless password.nil?
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 cmd_string << " > #{file}" unless file.nil?
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 stdout, stderr, status = Open3.capture3(cmd_string)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 raise Puppet::Error, _("stderr: '%{stderr}'" % { stderr: stderr }) if status != 0
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
16
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 { status: stdout.strip }
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 end
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 389
diff changeset
20 params = JSON.parse($stdin.read)
244
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 database = params['database']
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 user = params['user']
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 password = params['password']
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 file = params['file']
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 begin
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 result = get(file, database, user, password)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 puts result.to_json
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 exit 0
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 rescue Puppet::Error => e
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 puts({ status: 'failure', error: e.message }.to_json)
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 exit 1
48d3a1948e4d Update MySQL module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 end