6
0
Fork 0

Import __borg* from dot-cdist

This commit is contained in:
Timothée Floure 2021-01-13 16:33:58 +01:00
parent 6ae48831ae
commit ecd5398710
Signed by: tfloure
GPG Key ID: 4502C902C00A1E12
11 changed files with 142 additions and 0 deletions

29
type/__borg/manifest Normal file
View File

@ -0,0 +1,29 @@
#!/bin/sh
os=$(cat "${__global:?}/explorer/os")
case "$os" in
alpine|ubuntu|debian)
__package borgbackup
__package borgbackup
;;
*)
echo "This type does not support $os. Exiting." >&2
exit 1
;;
esac
repository=$(cat "$__object/parameter/repository")
if [ -f "$__object/parameter/exclude" ]; then
excludes=$(cat "$__object/parameter/exclude")
else
excludes="/sys /proc /dev /run"
fi
for path in $excludes; do
exclude_fragment="$exclude_fragment --exclude $path"
done
unknown_repo_warning_fragment="BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes"
borg_command="sh -c \"$unknown_repo_warning_fragment borg create $exclude_fragment --stats $repository::daily-\\\$(date -I) /\""
require="__package/borgbackup" __cron daily-backup --user root --command "$borg_command" --hour 2

View File

@ -0,0 +1 @@
exclude

View File

@ -0,0 +1 @@
repository

0
type/__borg/singleton Normal file
View File

View File

@ -0,0 +1,41 @@
#!/bin/sh
passphrase=
appendonly=
case "$(cat "${__object:?}/parameter/encryption")" in
none)
enc=none
;;
repokey)
enc=repokey
if [ -f "${__object:?}/parameter/passphrase" ];
then
passphrase="$(cat "${__object:?}/parameter/passphrase")"
else
echo "__borg_repo cannot use repokey encryption with no passphrase. Aborting." >&2;
exit 1;
fi
;;
*)
echo "$enc is not a known encryption mode for __borg_repo. Aborting." >&2
exit 1;
esac
if [ -f "${__object:?}/parameter/append-only" ];
then
appendonly='--append-only'
fi
if [ -f "${__object:?}/parameter/owner" ];
then
doas="sudo -u '$(cat "${__object:?}/parameter/owner")'"
fi
cat <<- EOF
set -x
if [ ! -d "/${__object_id:?}" ]; then
$doas BORG_NEW_PASSPHRASE=$passphrase borg init -e ${enc:?} $appendonly /${__object_id:?}
fi
EOF

46
type/__borg_repo/man.rst Normal file
View File

@ -0,0 +1,46 @@
cdist-type__borg_repo(7)
========================
NAME
----
cdist-type__borg_repo - Configure a borg repository on host
DESCRIPTION
-----------
Initializes a borg repository at the location specified in the
`${__object_id}`. Nothing is done if the repository already exists.
Currently, only `none` and `repokey` are supported as encryption modes;
`repokey` requires the `passphrase` argument to be given. The default is
`none`.
REQUIRED PARAMETERS
-------------------
encryption
The encryption to use.
OPTIONAL PARAMETERS
-------------------
passphrase
The passphrase to encrypt the keyfile with.
owner
Remote user owning the repository.
BOOLEAN PARAMETERS
------------------
append-only
If the repository is append-only
AUTHORS
-------
Joachim Desroches <joachim.desroches@epfl.ch>
COPYING
-------
Copyright \(C) 2020 Joachim Desroches. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

19
type/__borg_repo/manifest Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
os="$(cat "${__global:?}"/explorer/os)"
case "$os" in
"alpine")
borg_package=borgbackup
;;
*)
echo "__borg_repo is not yet implemented for os $os. Aborting." >&2;
exit 1;
esac
__package "$borg_package"
if [ -f "${__object:?}/parameter/owner" ];
then
__package sudo
fi

View File

@ -0,0 +1 @@
append-only

View File

@ -0,0 +1 @@
none

View File

@ -0,0 +1,2 @@
passphrase
owner

View File

@ -0,0 +1 @@
encryption