Compare commits

...

1 commit

Author SHA1 Message Date
e95153ca64
Add type to backup files using targz. 2020-08-17 14:35:35 +02:00
3 changed files with 77 additions and 0 deletions

43
type/__dirbackup/man.rst Normal file
View file

@ -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 <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.

31
type/__dirbackup/manifest Normal file
View file

@ -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

View file

@ -0,0 +1,3 @@
frequency
destination
keep