diff --git a/manifests/borg.pp b/manifests/borg.pp new file mode 100644 index 0000000..9052fdd --- /dev/null +++ b/manifests/borg.pp @@ -0,0 +1,84 @@ + + +class wmdeit_backup::borg ( + $repos = $borg_repos, + $scripts = $borg_scripts + +) + +inherits wmdeit_backup::params +{ + class {"wmdeit_backup::setup": + + }-> + package {$borg_packages: + ensure => installed + } + file {$scripts: + ensure => directory + } + +} + + +define wmdeit_backup::borg_backup +( + $server = $title, + $dirs = [], + $encryption = "keyfile", + $passphrase = "", + $ssh_user = 'root', + $ssh_port = '22', + $ssh_check_hostkey = 'no', + + $weekday = undef, + $hour = '0', + $minute = '0', + +) { + $scripts = $wmdeit_backup::borg::scripts + $repos = $wmdeit_backup::borg::repos + + $borg_cmd = $wmdeit_backup::borg::borg_cmd + + $repo = "$repos/$title" + + exec {"borg_init_$title": + command => "/bin/sh -c 'export BORG_PASSPHRASE=$passphrase && $borg_cmd init -e $encryption $repo'", + unless => "/bin/sh -c 'export BORG_PASSPHRASE=$passphrase && $borg_cmd list -e $encryption $repo'", +# creates => $repo + } + + $p = $dirs.map | $str | { ".$str" } + $backup_dirs = join($p," ") + $mnt = "$wmdeit_backup::borg::borg_mnt/$title" + $script_name = "$scripts/$title.sh" + + file {$mnt: + ensure => directory + }-> + file {$script_name: + ensure => file, + content => "#!/bin/sh +export BORG_PASSPHRASE=$passphrase +D=`date +%F` +$wmdeit_backup::borg::sshfs_cmd -oStrictHostKeyChecking=$ssh_check_hostkey -oPort=$ssh_port $ssh_user@$server:/ $mnt +cd $mnt +CMD=\"$borg_cmd create ${repo}::$title-\${D} $backup_dirs\" +\$CMD +cd / +umount $mnt +" + + + }-> + cron {"borg-$title": + weekday => $weekday, + hour => $hour, + minute => $minute, + command => "/bin/sh $script_name" + } + + + +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..753dbeb --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,27 @@ +# +# params.pp +# + +class wmdeit_backup::params { + + case $::osfamily { + 'FreeBSD':{ + $borg_packages = [ + "py37-borgbackup", + "fusefs-sshfs", + ] + + $sshfs_cmd = '/usr/local/bin/sshfs' + $borg_cmd = "/usr/local/bin/borg" + } + default: { + + }} + + $borg_repos = "/tank/backups" + $borg_scripts = "/root/borg" + $borg_mnt = "/mnt" +} + + + diff --git a/manifests/setup.pp b/manifests/setup.pp new file mode 100644 index 0000000..a6c3a45 --- /dev/null +++ b/manifests/setup.pp @@ -0,0 +1,18 @@ + + +class wmdeit_backup::setup +{ + + case $::osfamily { + 'FreeBSD':{ + exec {"/sbin/kldload fusefs": + unless => "/sbin/kldstat -n fusefs" + } + + } + default: { + + }} +} + +