coreos-home-server/host/base/systemd/container-volume-backup@.service

20 lines
937 B
SYSTEMD
Raw Normal View History

[Unit]
Description=Backup for Container Volume %I
[Service]
Type=oneshot
SyslogIdentifier=%N
ExecStartPre=/bin/install --mode 0700 --directory %S/backups/coreos-home-server/%i
ExecStart=/bin/podman run --replace --rm --name %p-%i --entrypoint /bin/bash \
--volume %i:/data:z,ro \
--volume %S/backups/coreos-home-server/%i:/backup:z \
docker.io/debian:bullseye-slim -c \
'test -f /backup/%i-latest.tar.gz && \
test "$(find /data -type f -newer /backup/%i-latest.tar.gz -print -quit | wc -l)" -eq 0 && exit 0; \
name="%i-$(date +%%w%%H)" && \
tar --verbose --create --gzip --file "/backup/$name.tar.gz" --directory /data . && \
ln --force "/backup/$name.tar.gz" /backup/%i-latest.tar.gz'
[Install]
WantedBy=multi-user.target