Puppet Class: bitbucket::backup

Defined in:
manifests/backup.pp

Overview

Class: bitbucket::backup

This installs the bitbucket backup client

Parameters:

  • manage_backup (Any) (defaults to: $bitbucket::manage_backup)
  • ensure (Any) (defaults to: $bitbucket::backup_ensure)
  • schedule_hour (Any) (defaults to: $bitbucket::backup_schedule_hour)
  • schedule_minute (Any) (defaults to: $bitbucket::backup_schedule_minute)
  • backupuser (Any) (defaults to: $bitbucket::backupuser)
  • backuppass (Any) (defaults to: $bitbucket::backuppass)
  • version (Any) (defaults to: $bitbucket::backupclient_version)
  • product (Any) (defaults to: $bitbucket::product)
  • backup_format (Any) (defaults to: $bitbucket::backup_format)
  • homedir (Any) (defaults to: $bitbucket::homedir)
  • user (Any) (defaults to: $bitbucket::user)
  • group (Any) (defaults to: $bitbucket::group)
  • deploy_module (Any) (defaults to: $bitbucket::deploy_module)
  • download_url (Any) (defaults to: $bitbucket::backupclient_url)
  • backup_home (Any) (defaults to: $bitbucket::backup_home)
  • javahome (Any) (defaults to: $bitbucket::javahome)
  • keep_age (Any) (defaults to: $bitbucket::backup_keep_age)
  • manage_usr_grp (Any) (defaults to: $bitbucket::manage_usr_grp)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'manifests/backup.pp', line 6

class bitbucket::backup(
  $manage_backup        = $bitbucket::manage_backup,
  $ensure               = $bitbucket::backup_ensure,
  $schedule_hour        = $bitbucket::backup_schedule_hour,
  $schedule_minute      = $bitbucket::backup_schedule_minute,
  $backupuser           = $bitbucket::backupuser,
  $backuppass           = $bitbucket::backuppass,
  $version              = $bitbucket::backupclient_version,
  $product              = $bitbucket::product,
  $backup_format        = $bitbucket::backup_format,
  $homedir              = $bitbucket::homedir,
  $user                 = $bitbucket::user,
  $group                = $bitbucket::group,
  $deploy_module        = $bitbucket::deploy_module,
  $download_url         = $bitbucket::backupclient_url,
  $backup_home          = $bitbucket::backup_home,
  $javahome             = $bitbucket::javahome,
  $keep_age             = $bitbucket::backup_keep_age,
  $manage_usr_grp       = $bitbucket::manage_usr_grp,
  ) {

  if $manage_backup {
    $appdir = "${backup_home}/${product}-backup-client-${version}"

    file { $backup_home:
      ensure => 'directory',
      owner  => $user,
      group  => $group,
    }
    file { "${backup_home}/archives":
      ensure => 'directory',
      owner  => $user,
      group  => $group,
    }

    $file = "${product}-backup-distribution-${version}.${backup_format}"

    file { $appdir:
      ensure => 'directory',
      owner  => $user,
      group  => $group,
    }

    file { '/var/tmp/downloadurl':
      content => "${download_url}/${version}/${file}",
    }

    case $deploy_module {
      'staging': {
        require staging
        staging::file { $file:
          source  => "${download_url}/${version}/${file}",
          timeout => 1800,
        } ->
        staging::extract { $file:
          target  => $appdir,
          creates => "${appdir}/lib",
          strip   => 1,
          user    => $user,
          group   => $group,
          require => File[$appdir],
        }

        if $manage_usr_grp {
          User[$user] -> Staging::Extract[$file]
        }
      }
      'archive': {
        archive { "/tmp/${file}":
          ensure       => present,
          extract      => true,
          extract_path => $backup_home,
          source       => "${download_url}/${version}/${file}",
          user         => $user,
          group        => $group,
          creates      => "${appdir}/lib",
          cleanup      => true,
          before       => File[$appdir],
        }
      }
      default: {
        fail('deploy_module parameter must equal "archive" or staging""')
      }
    }

    if $javahome {
      $java_bin = "${javahome}/bin/java"
    } else {
      $java_bin = '/usr/bin/java'
    }

    # Enable Cronjob
    $backup_cmd = "${java_bin} -Dbitbucket.password='${backuppass}'\
 -Dbitbucket.user=\"${backupuser}\"\
 -Dbitbucket.baseUrl=\"http://localhost:${bitbucket::tomcat_port}\"\
 -Dbitbucket.home=${homedir} -Dbackup.home=${backup_home}/archives\
 -jar ${appdir}/bitbucket-backup-client.jar"

    cron { 'Backup Bitbucket':
      ensure  => $ensure,
      command => $backup_cmd,
      user    => $user,
      hour    => $schedule_hour,
      minute  => $schedule_minute,
    }

    tidy { 'remove_old_archives':
      path    => "${backup_home}/archives",
      age     => $keep_age,
      matches => '*.tar',
      type    => 'mtime',
      recurse => 2,
    }
  }

}