Add type to backup files using targz.

parent ce20c676
Pipeline #2127 passed with stage
in 30 seconds
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 <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.
#!/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
frequency
destination
keep
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment