diff --git a/type/__dirbackup/man.rst b/type/__dirbackup/man.rst new file mode 100644 index 0000000..fab8e42 --- /dev/null +++ b/type/__dirbackup/man.rst @@ -0,0 +1,43 @@ +cdist-type__dirbackup(7) +======================== + +NAME +---- +cdist-type__dirbackup - Periodically tar a directory somewhere else. + +DESCRIPTION +----------- + +This type writes a script to tar a directory somewhere else accessible through +a filesystem, keeping only copies older than the requested days. The source +directory (or file, the type doesn't actually make a difference) to be targz'd +is expected as "$__object_id". + +REQUIRED PARAMETERS +------------------- + +destination + The directory in which the backups are to be copied. Expects an absolute + path. It will be created if it does not exist, but beware as it will then + have cdist's default restrictive permissions. + +frequency + The directory in `/etc/periodic` to link the backup script to. Usual existing + values are `15mn`, `hourly`, `daily`, `weekly`, `monthly`. Values here depend + on your distribution an cron setup; this type currently only supports Alpine + Linux, who's default values are the above mentioned. + +keep + The amount of days to keep data. A natural integer is expected, it is + directly passed on to the `-mtime` argument of `find(1)`. + +AUTHORS +------- +Joachim Desroches + +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. diff --git a/type/__dirbackup/manifest b/type/__dirbackup/manifest new file mode 100644 index 0000000..04a362a --- /dev/null +++ b/type/__dirbackup/manifest @@ -0,0 +1,31 @@ +#!/bin/sh + +os="$(cat "${__global:?}"/explorer/os)" + +case "$os" in + alpine) + : + ;; + *) + echo "This type has no implementation for $os. Aborting." >&2 + exit 1 + ;; +esac + +scriptname="dirbackup-$(dd if=/dev/random bs=1 count=16 | tr -dC '[:alnum:]')" + +destination="$(cat "${__object:?}/parameter/destination")" +frequency="$(cat "${__object:?}/parameter/frequency")" +keep="$(cat "${__object:?}/parameter/keep")" +src="/${__object_id:?}" + +srcstrip="$(basename "$src")" + +__directory "$destination" --parents +__file "/etc/periodic/$frequency/$scriptname" \ + --mode 0755 \ + --source - <<- EOF + #!/bin/sh + tar -czpf "$destination/$srcstrip-\$(date -I).tar.gz" -C '$(dirname "$src")' '$srcstrip' + find '$destination' -mtime '$keep' -exec rm {} \; + EOF diff --git a/type/__dirbackup/parameter/required b/type/__dirbackup/parameter/required new file mode 100644 index 0000000..fdeb399 --- /dev/null +++ b/type/__dirbackup/parameter/required @@ -0,0 +1,3 @@ +frequency +destination +keep