2021-06-25 08:36:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 = [],
|
2021-06-25 15:28:11 +00:00
|
|
|
$encryption = "repokey",
|
|
|
|
$passphrase = "`/bin/cat /root/borg_passphrase.txt`",
|
2021-06-25 08:36:35 +00:00
|
|
|
$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
|
2021-06-25 15:28:11 +00:00
|
|
|
$sshfs_options = $wmdeit_backup::borg::sshfs_options
|
|
|
|
|
2021-06-25 08:36:35 +00:00
|
|
|
|
|
|
|
$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`
|
2021-06-25 15:28:11 +00:00
|
|
|
$wmdeit_backup::borg::sshfs_cmd $sshfs_options -oStrictHostKeyChecking=$ssh_check_hostkey -oPort=$ssh_port $ssh_user@$server:/ $mnt
|
2021-06-25 08:36:35 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|