Puppet Class: db2_profile::database::db_standby

Defined in:
manifests/database/db_standby.pp

Summary

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

Overview

db2_profile::database::db_standby

When the named database does not yet run on the server, Puppet will use the backup at the ‘backup_path` to create an intial running database and set it in standby mode.

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

Parameters:

  • list (Hash)

    A hash of ‘db2_database` entries.

  • 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.

  • backup_path (Stdlib::Absolutepath)

    The path where DB2 can find the backup of this database. Before applying this class, you’ll have to use a ‘before_db_standby` class to copy the backup from the primary DB2 node to the location specified by this parameter.

  • archive_path (String[1])

    The path to use for DB2 archiving.

  • group (String[1])

    The group to use for the archive and backup directories.

  • owner (String[1])

    The owner to use for the archive and backup directories.

  • 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,
      ...
    }
    


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
89
90
91
92
93
94
95
96
97
98
99
100
# File 'manifests/database/db_standby.pp', line 43

class db2_profile::database::db_standby (
  String[1]            $archive_path,
  Stdlib::Absolutepath $backup_path,
  String[1]            $database,
  String[1]            $group,
  String[1]            $instance,
  Hash                 $list,
  String[1]            $owner,
  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]:
    ensure => 'directory',
    owner  => $owner,
    group  => $group,
  }

  if $facts['db2_databases'].dig("${instance}/${database}") == undef {
    echo { "Ensure DB2 standby database based on backup in '${$backup_path}'":
      withpath => false,
    }

    exec { "restore backup for ${database}":
      command     => "/home/${instance}/sqllib/bin/db2 restore database ${database} from ${backup_path}",
      cwd         => $backup_path,
      user        => $instance,
      environment => "DB2INSTANCE=${instance}",
      logoutput   => $logoutput,
    }

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

    $require = Exec["restore backup for ${database}"]
    $before  = Exec["set database '${database}' as standby"]
  } else {
    $require = undef
    $before  = undef
  }

  $list.each |$name, $properties| {
    db2_database { $name:
      allow_restart => true,
      *             => $properties,
      require       => $require,
      before        => $before,
    }
  }
}