cdist-contrib/type/__dirbackup/manifest

32 lines
745 B
Bash

#!/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