coreos-home-server/config/common/systemd/container-volume-backup@.service
Alex Palaistras 41328342b3 Implement basic volume backup and restore mechanism
This commit implements three new services, specifically:

  - The `container-volume` service, which applies to a specific volume
    name and ensures this exists. This is mainly useful as a dependency
    to other services, as Podman will create named volumes itself if
    needed.

  - The `container-volume-backup` service, which creates a `tar.gz`
    snapshot of the given volume's contents in `/var/lib/backups`.

  - The `container-volume-restore` service, which populates an empty
    volume from a pre-existing file in `/var/lib/backups`, presumably
    created by `container-volume-backup`.

These are then be used to automatically create volume snapshots every 12
hours, rolling over every 7 days.
2021-08-14 22:38:17 +01:00

17 lines
715 B
Desktop File

[Unit]
Description=Backup for container volume %I
[Service]
Type=oneshot
ExecStartPre=/bin/install --mode 0700 --directory %S/backups/coreos-home-server/%i
ExecStart=/bin/podman run --replace --pull never --rm --name %p-%i \
--volume %i:/data:z,ro \
--volume %S/backups/coreos-home-server/%i:/backups:z \
--entrypoint /bin/bash docker.io/debian:stable-slim \
-c 'env name="%i-$(date +%%w%%H)" \
tar -cvpzf "/backups/${name}.tar.gz" -C /data . && \
ln --force "/backups/${name}.tar.gz" /backups/%i-latest.tar.gz'
[Install]
WantedBy=multi-user.target