rsync.pp 3.02 KB
Newer Older
Silvio Rhatto's avatar
Silvio Rhatto committed
1 2 3 4
# Run rsync as part of a backupninja run.
# Based on backupninja::rdiff

define backupninja::rsync(
5
  $order = 90, $ensure = present,
6
  $user = false, $home = "/home/${user}-${name}", $host = false,
7
  $ssh_dir_manage = true, $ssh_dir = "${home}/.ssh", $authorized_keys_file = 'authorized_keys',
8
  $installuser = true, $keymanage = $backupninja::keymanage, $key = false, $backuptag = "backupninja-${::fqdn}",
9
  $backupkeytype = $backupninja::keytype, $backupkeystore = $backupninja::keystore, $extras = false,
10
  $nagios_description = "backups-${name}", $subfolder = 'rsync',
Silvio Rhatto's avatar
Silvio Rhatto committed
11 12

  $log = false, $partition = false, $fscheck = false, $read_only = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
13
  $mountpoint = false, $backupdir = false, $format = false, $days = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
14 15 16
  $keepdaily = false, $keepweekly = false, $keepmonthly = false, $lockfile = false,
  $nicelevel = 0, $enable_mv_timestamp_bug = false, $tmp = false, $multiconnection = false,

Silvio Rhatto's avatar
Silvio Rhatto committed
17
  $exclude_vserver = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
18 19 20 21 22 23
  $exclude = [ "/home/*/.gnupg", "/home/*/.local/share/Trash", "/home/*/.Trash",
               "/home/*/.thumbnails", "/home/*/.beagle", "/home/*/.aMule",
               "/home/*/gtk-gnutella-downloads" ],
  $include = [ "/var/spool/cron/crontabs", "/var/backups", "/etc", "/root",
               "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ],

Silvio Rhatto's avatar
Silvio Rhatto committed
24
  $testconnect = false, $protocol = false, $ssh = false, $port = false,
25 26 27
  $bandwidthlimit = false, $remote_rsync = false, $id_file = false,
  $batch = false, $batchbase = false, $numericids = false, $compress = false,
  $fakesuper = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
28

29
  $initscripts = false, $service = false,
Silvio Rhatto's avatar
Silvio Rhatto committed
30

31
  $rm = false, $cp = false, $touch = false, $mv = false, $fsck = false)
Silvio Rhatto's avatar
Silvio Rhatto committed
32
{
33
  # install client dependencies
34
  ensure_resource('package', 'rsync', {'ensure' => $backupninja::ensure_rsync_version})
Silvio Rhatto's avatar
Silvio Rhatto committed
35

Silvio Rhatto's avatar
Silvio Rhatto committed
36 37 38
  # Right now just local origin with remote destination is supported.
  $from = 'local'
  $dest = 'remote'
Silvio Rhatto's avatar
Silvio Rhatto committed
39

Silvio Rhatto's avatar
Silvio Rhatto committed
40 41 42 43
  case $dest {
    'remote': {
      case $host { false: { err("need to define a host for remote backups!") } }

44
      $directory = "${home}/${subfolder}/"
Silvio Rhatto's avatar
Silvio Rhatto committed
45 46 47 48

      backupninja::server::sandbox { "${user}-${name}":
        user                 => $user,
        host                 => $host,
49
        dir                  => $home,
Silvio Rhatto's avatar
Silvio Rhatto committed
50 51 52 53 54
        manage_ssh_dir       => $ssh_dir_manage,
        ssh_dir              => $ssh_dir,
        key                  => $key,
        authorized_keys_file => $authorized_keys_file,
        installuser          => $installuser,
55
        backuptag            => $backuptag,
Silvio Rhatto's avatar
Silvio Rhatto committed
56 57
        keytype              => $backupkeytype,
        backupkeys           => $backupkeystore,
58
        nagios_description  => $nagios_description
Silvio Rhatto's avatar
Silvio Rhatto committed
59 60
      }
     
61
      backupninja::key { "${user}-${name}":
Silvio Rhatto's avatar
Silvio Rhatto committed
62
        user       => $user,
63
        keymanage  => $keymanage,
Silvio Rhatto's avatar
Silvio Rhatto committed
64 65 66 67 68 69
        keytype    => $backupkeytype,
        keystore   => $backupkeystore,
      }
    }
  }

70
  file { "${backupninja::configdir}/${order}_${name}.rsync":
Silvio Rhatto's avatar
Silvio Rhatto committed
71 72 73 74 75
    ensure  => $ensure,
    content => template('backupninja/rsync.conf.erb'),
    owner   => root,
    group   => root,
    mode    => 0600,
76
    require => File["${backupninja::configdir}"]
Silvio Rhatto's avatar
Silvio Rhatto committed
77 78
  }
}