restic.sh (1192B)
1 #!/usr/bin/env bash 2 3 set -o errexit 4 set -o nounset 5 set -o xtrace 6 7 apt-get install -y restic rclone ca-certificates 8 9 # Configure restic repo 10 mkdir -p /root/.config/restic 11 mkdir -p /root/.config/rclone 12 13 cat <<EOF > /root/.config/restic/env 14 # https://restic.readthedocs.io/en/latest/040_backup.html#environment-variables 15 RESTIC_REPOSITORY="$RESTIC_REPOSITORY" 16 RESTIC_PASSWORD="$RESTIC_PASSWORD" 17 EOF 18 cat <<EOF > /root/.config/rclone/rclone.conf 19 [pcloud] 20 type = pcloud 21 hostname = eapi.pcloud.com 22 EOF 23 24 25 # Install systemd service unit 26 cat <<'EOF' > /etc/systemd/system/restic.service 27 [Unit] 28 Description=Create a backup with restic 29 30 [Service] 31 Type=oneshot 32 EnvironmentFile=/root/.config/restic/env 33 ExecStart=-/usr/bin/restic init 34 ExecStart=-/usr/bin/restic backup /host-nfs 35 ExecStart=-/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 36 ExecStart=-/usr/bin/restic prune 37 38 [Install] 39 WantedBy=default.target 40 EOF 41 42 # Install systemd timer 43 cat <<'EOF' > /etc/systemd/system/restic.timer 44 [Unit] 45 Description=Create a backup with restic 46 47 [Timer] 48 Unit=restic.service 49 OnCalendar=*-*-* 01:03:00 50 51 [Install] 52 WantedBy=timers.target 53 EOF 54 55 systemctl enable restic.timer 56 systemctl start restic.timer