Puppet Class: db2_profile::database::db_primary

Defined in:
manifests/database/db_primary.pp

Summary

When the property `db2_profile::database::primary` is set, and the current node is the designated primary server, this class will be applied.

Overview

db2_profile::database::db_primary

It will set the database in archiving mode, create a backup and then set the database in primary mode.

See the file “LICENSE” for the full license governing this code.

Parameters:

  • instance (String[1])

    The instance to use for the database.

  • database (String[1])

    The database name to use for the primary or standby database. this needs to be the same on the primary and standby nodes.

  • archive_path (Stdlib::Absolutepath)

    The path to use for DB2 archiving.

  • backup_path (Stdlib::Absolutepath)

    The location to put the DB2 database backup.

  • owner (String[1])

    The owner to use for the archive and backup directories.

  • group (String[1])

    The group to use for the archive and backup directories.

  • wait_time (Integer)

    The in seconds to wait to set he database in primary mode aftercthe backup has been made.

  • logoutput (Variant[Boolean,Enum['on_failure']]) (defaults to: lookup({ name => 'logoutput', default_value => 'on_failure' }))

    If you want to see the output of the ‘exec` resources in the type, you can set this value to `true`. The default is `on_failure`. Here is an example on how to use this:

    class { '::db2_install::...':
      ...
      logoutput => true,
      ...
    }
    


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'manifests/database/db_primary.pp', line 42

class db2_profile::database::db_primary (
  Stdlib::Absolutepath $archive_path,
  Stdlib::Absolutepath $backup_path,
  String[1]            $database,
  String[1]            $group,
  String[1]            $instance,
  String[1]            $owner,
  Integer              $wait_time,
  Variant[Boolean,Enum['on_failure']]
  $logoutput = lookup({ name => 'logoutput', default_value => 'on_failure' })
) {
  easy_type::debug_evaluation() # Show local variable on extended debug

  echo { "Ensure DB2 archiving path '${$archive_path}'":
    withpath => false,
  }
  file { [$archive_path, $backup_path]:
    ensure => 'directory',
    owner  => $owner,
    group  => $group,
  }

  if $facts['db2_databases'].dig("${instance}/${database}") == undef {
    exec { "Set database ${database} in archiving mode":
      command     => "/home/${instance}/sqllib/bin/db2 update db cfg for ${database} using LOGARCHMETH1 \"DISK:${archive_path}\"",
      unless      => "/home/${instance}/sqllib/bin/db2 get database config for ${database} | /usr/bin/grep \"(LOGARCHMETH1) = DISK:${archive_path}\"",
      user        => $instance,
      environment => "DB2INSTANCE=${instance}",
      logoutput   => $logoutput,
    }

    -> exec { "create backup for ${database}":
      command     => "/bin/sleep ${wait_time};/home/${instance}/sqllib/bin/db2 backup database ${database} to ${backup_path}",
      cwd         => $backup_path,
      user        => $instance,
      environment => "DB2INSTANCE=${instance}",
      logoutput   => $logoutput,
    }

    -> exec { "set database '${database}' as primary":
      command     => "/home/${instance}/sqllib/bin/db2 start hadr on database ${database} as primary by force",
      user        => $instance,
      environment => "DB2INSTANCE=${instance}",
      logoutput   => $logoutput,
    }
  }
}