From 1d1aee1c6a89b117ab4b4c69bed5ca49c585ce85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Sun, 5 Jun 2022 01:09:23 +0200 Subject: [PATCH] Add plain restic example --- etc/systemd/user/restic-check@.service | 16 ++++++++++++++++ etc/systemd/user/restic-check@.timer | 9 +++++++++ etc/systemd/user/restic-create@.service | 16 ++++++++++++++++ etc/systemd/user/restic-create@.timer | 9 +++++++++ etc/systemd/user/restic-prune@.service | 16 ++++++++++++++++ etc/systemd/user/restic-prune@.timer | 9 +++++++++ etc/systemd/user/resticwrapper.service | 11 +++++++---- etc/systemd/user/resticwrapper.timer | 2 +- sync | 4 ++-- usr/share/doc/restic/mybackup-check.sh | 3 +++ usr/share/doc/restic/mybackup-create.sh | 11 +++++++++++ usr/share/doc/restic/mybackup-prune.sh | 3 +++ usr/share/doc/restic/mybackup.env | 14 ++++++++++++++ usr/share/doc/restic/mybackup.exclude | 3 +++ usr/share/doc/restic/mybackup.include | 2 ++ 15 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 etc/systemd/user/restic-check@.service create mode 100644 etc/systemd/user/restic-check@.timer create mode 100644 etc/systemd/user/restic-create@.service create mode 100644 etc/systemd/user/restic-create@.timer create mode 100644 etc/systemd/user/restic-prune@.service create mode 100644 etc/systemd/user/restic-prune@.timer create mode 100755 usr/share/doc/restic/mybackup-check.sh create mode 100755 usr/share/doc/restic/mybackup-create.sh create mode 100755 usr/share/doc/restic/mybackup-prune.sh create mode 100644 usr/share/doc/restic/mybackup.env create mode 100644 usr/share/doc/restic/mybackup.exclude create mode 100644 usr/share/doc/restic/mybackup.include diff --git a/etc/systemd/user/restic-check@.service b/etc/systemd/user/restic-check@.service new file mode 100644 index 0000000..2b92d33 --- /dev/null +++ b/etc/systemd/user/restic-check@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run restic check script for %I utilizing ~/.config/restic/%I-check.sh file using env ~/.config/restic/%I.env +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target + +[Service] +Type=oneshot +ExecStart=sh %h/.config/restic/%I-check.sh +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" +EnvironmentFile=%h/.config/restic/%I.env + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/user/restic-check@.timer b/etc/systemd/user/restic-check@.timer new file mode 100644 index 0000000..2d579d0 --- /dev/null +++ b/etc/systemd/user/restic-check@.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run restic check script for %I utilizing HOME/.config/restic/%I-check.sh file + +[Timer] +OnCalendar=Wed 22:00:00 +Persistent=false + +[Install] +WantedBy=timers.target diff --git a/etc/systemd/user/restic-create@.service b/etc/systemd/user/restic-create@.service new file mode 100644 index 0000000..c5f7b21 --- /dev/null +++ b/etc/systemd/user/restic-create@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run restic create script for %I utilizing ~/.config/restic/%I-create.sh file using env ~/.config/restic/%I.env +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target + +[Service] +Type=oneshot +ExecStart=sh %h/.config/restic/%I-create.sh +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" +EnvironmentFile=%h/.config/restic/%I.env + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/user/restic-create@.timer b/etc/systemd/user/restic-create@.timer new file mode 100644 index 0000000..526bda4 --- /dev/null +++ b/etc/systemd/user/restic-create@.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run restic create script for %I utilizing HOME/.config/restic/%I-create.sh file + +[Timer] +OnCalendar=23:00 +Persistent=false + +[Install] +WantedBy=timers.target diff --git a/etc/systemd/user/restic-prune@.service b/etc/systemd/user/restic-prune@.service new file mode 100644 index 0000000..2b92d33 --- /dev/null +++ b/etc/systemd/user/restic-prune@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Run restic check script for %I utilizing ~/.config/restic/%I-check.sh file using env ~/.config/restic/%I.env +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target + +[Service] +Type=oneshot +ExecStart=sh %h/.config/restic/%I-check.sh +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" +EnvironmentFile=%h/.config/restic/%I.env + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/user/restic-prune@.timer b/etc/systemd/user/restic-prune@.timer new file mode 100644 index 0000000..d11d5d9 --- /dev/null +++ b/etc/systemd/user/restic-prune@.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run restic prune script for %I utilizing HOME/.config/restic/%I-prune.sh file + +[Timer] +OnCalendar=Wed 23:00:00 +Persistent=false + +[Install] +WantedBy=timers.target diff --git a/etc/systemd/user/resticwrapper.service b/etc/systemd/user/resticwrapper.service index 1cdaca4..4d7f3f1 100644 --- a/etc/systemd/user/resticwrapper.service +++ b/etc/systemd/user/resticwrapper.service @@ -1,12 +1,15 @@ [Unit] Description=Run resticwrapper -#OnFailure=systemd_failure_notify@%n.service +OnFailure=systemd_failure_notify@%n.service +Wants=network-online.target +After=network-online.target +Requires=network-online.target [Service] Type=oneshot ExecStart=resticwrapper -#ExecStart=borgwrapper /home/myUser/resticwrapper-custom.conf -#Environment="SSH_AUTH_SOCK=/run/user/myUserId/keyring/ssh" +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:%h/.bin" +Environment="SSH_AUTH_SOCK=/run/user/%u/keyring/ssh" [Install] -WantedBy=default.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/systemd/user/resticwrapper.timer b/etc/systemd/user/resticwrapper.timer index 63e26ba..818b818 100644 --- a/etc/systemd/user/resticwrapper.timer +++ b/etc/systemd/user/resticwrapper.timer @@ -2,7 +2,7 @@ Description=Run resticwrapper [Timer] -OnCalendar=20:00 +OnCalendar=23:00 Persistent=false [Install] diff --git a/sync b/sync index be6aa53..ba59467 100755 --- a/sync +++ b/sync @@ -15,7 +15,7 @@ usage() { echo ""; echo "- Press 4 to list command line users for sync"; echo ""; - echo "- Press 5 to sync the git folder's '/usr/local/bin' with system's '/usr/local/bin'"; + echo "- Press 5 to sync the git folder's '/usr' with system's '/usr'"; echo "---"; echo "Press 0 or [CTRL+C] to exit"; } @@ -100,7 +100,7 @@ menu() { echo $u; done elif [ "$menuInput" = "5" ]; then - sudo rsync -r -t -v --chown=root:root --progress $(pwd)/usr/local/bin/ /usr/local/bin/ + sudo rsync -r -t -v --chown=root:root --progress $(pwd)/usr/ /usr/ echo ""; elif [ "$menuInput" = "0" ]; then exit 0; diff --git a/usr/share/doc/restic/mybackup-check.sh b/usr/share/doc/restic/mybackup-check.sh new file mode 100755 index 0000000..a1276c2 --- /dev/null +++ b/usr/share/doc/restic/mybackup-check.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/usr/bin/restic check \ No newline at end of file diff --git a/usr/share/doc/restic/mybackup-create.sh b/usr/share/doc/restic/mybackup-create.sh new file mode 100755 index 0000000..236667b --- /dev/null +++ b/usr/share/doc/restic/mybackup-create.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +/usr/bin/restic backup \ + --one-file-system \ + --exclude-file /home/myuser/.config/restic/mybackup.exclude \ + --files-from /home/myuser/.config/restic/mybackup.include + +/usr/bin/restic forget \ + --keep-daily 7 \ + --keep-weekly 4 \ + --keep-monthly 3 \ No newline at end of file diff --git a/usr/share/doc/restic/mybackup-prune.sh b/usr/share/doc/restic/mybackup-prune.sh new file mode 100755 index 0000000..6583e41 --- /dev/null +++ b/usr/share/doc/restic/mybackup-prune.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/usr/bin/restic prune \ No newline at end of file diff --git a/usr/share/doc/restic/mybackup.env b/usr/share/doc/restic/mybackup.env new file mode 100644 index 0000000..878317e --- /dev/null +++ b/usr/share/doc/restic/mybackup.env @@ -0,0 +1,14 @@ +# If you're using sftp with a special key, it's recommended to set an +# alias for the specific host and use it in the repository name +# +# ~/.ssh/config +# Host restic-mybackup +# HostName 192.168.1.2 +# Port 22 +# User backup +# IdentityFile ~/.ssh/backup + +RESTIC_CACHE_DIR="..." +RESTIC_PASSWORD="..." +#RESTIC_REPOSITORY="sftp://restic-mybackup//my/remote/path" +RESTIC_REPOSITORY="..." \ No newline at end of file diff --git a/usr/share/doc/restic/mybackup.exclude b/usr/share/doc/restic/mybackup.exclude new file mode 100644 index 0000000..926e2d6 --- /dev/null +++ b/usr/share/doc/restic/mybackup.exclude @@ -0,0 +1,3 @@ +/home/lost+found +/home/**/.cache +*.bak/** \ No newline at end of file diff --git a/usr/share/doc/restic/mybackup.include b/usr/share/doc/restic/mybackup.include new file mode 100644 index 0000000..e78cb33 --- /dev/null +++ b/usr/share/doc/restic/mybackup.include @@ -0,0 +1,2 @@ +/home/myuser +/etc \ No newline at end of file