view 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
line wrap: on
line source

#!/opt/puppetlabs/puppet/bin/ruby
# frozen_string_literal: true

require 'json'
require 'open3'
require 'puppet'

def get(file, database, user, password)
  cmd_string = 'mysqldump'
  cmd_string << " --databases #{database}" unless database.nil?
  cmd_string << " --user=#{user}" unless user.nil?
  cmd_string << " --password=#{password}" unless password.nil?
  cmd_string << " > #{file}" unless file.nil?
  stdout, stderr, status = Open3.capture3(cmd_string)
  raise Puppet::Error, _("stderr: '%{stderr}'" % { stderr: stderr }) if status != 0

  { status: stdout.strip }
end

params = JSON.parse($stdin.read)
database = params['database']
user = params['user']
password = params['password']
file = params['file']

begin
  result = get(file, database, user, password)
  puts result.to_json
  exit 0
rescue Puppet::Error => e
  puts({ status: 'failure', error: e.message }.to_json)
  exit 1
end