diff --git a/home/private_bin/executable_restic-othalan b/home/private_bin/executable_restic-othalan new file mode 100644 index 0000000..3c5a18d --- /dev/null +++ b/home/private_bin/executable_restic-othalan @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -a +source "$HOME/.config/restic/othalan.env" +declare -a flags + +# if [[ "$1" == "backup" ]]; then +# flags=( +# "--exclude-file" "$HOME/.config/restic/excludes.txt" +# "--exclude-file" "$HOME/.conda/environments.txt" +# ) +# fi +# +# echo "${flags[@]}" +# assumes subcommand always comes first +case $1 in + -*) restic "$@" && exit "$?";; + backup) cmd=backup; shift;; + *) cmd="$1"; shift;; +esac + +if [[ $cmd == "backup" ]]; then + flags=( + "--exclude-file" "$HOME/.config/restic/excludes.txt" + "--exclude-file" "$HOME/.conda/environments.txt" + ) +fi + + +# echo restic "$@" "${flags[@]}" + +restic "$cmd" "${flags[@]}" "$@" diff --git a/home/private_dot_config/restic/othalan.env b/home/private_dot_config/restic/othalan.env new file mode 100644 index 0000000..a06a878 --- /dev/null +++ b/home/private_dot_config/restic/othalan.env @@ -0,0 +1,11 @@ +RESTIC_REPOSITORY=rclone:g:othalan +RESTIC_PASSWORD_FILE=/home/daylin/.config/restic/othalan-pass +BACKUP_EXCLUDES=" +--exclude-file /home/daylin/.config/restic/excludes.txt +--exclude-file /home/daylin/.conda/environments.txt +" +RETENTION_DAYS=7 +RETENTION_WEEKS=4 +RETENTION_MONTHS=6 +RETENTION_YEARS=3 +BACKUP_PATHS="/home/daylin/dev /home/daylin/stuff" diff --git a/home/private_dot_config/systemd/user/restic-backup.service b/home/private_dot_config/systemd/user/restic-backup.service new file mode 100644 index 0000000..c1feaa7 --- /dev/null +++ b/home/private_dot_config/systemd/user/restic-backup.service @@ -0,0 +1,21 @@ +;ref: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/ + +[Unit] +Description=Restic backup service + +[Service] +Type=oneshot +ExecStart=restic backup \ + --verbose \ + --one-file-system \ + --tag systemd.timer \ + $BACKUP_EXCLUDES $BACKUP_PATHS +ExecStartPost=restic forget \ + --verbose \ + --tag systemd.timer \ + --group-by "paths,tags" \ + --keep-daily $RETENTION_DAYS \ + --keep-weekly $RETENTION_WEEKS \ + --keep-monthly $RETENTION_MONTHS \ + --keep-yearly $RETENTION_YEARS +EnvironmentFile=%h/.config/restic/othalan.env diff --git a/home/private_dot_config/systemd/user/restic-backup.timer b/home/private_dot_config/systemd/user/restic-backup.timer new file mode 100644 index 0000000..bc8b203 --- /dev/null +++ b/home/private_dot_config/systemd/user/restic-backup.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Backup with restic daily + +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/home/private_dot_config/systemd/user/restic-prune.service b/home/private_dot_config/systemd/user/restic-prune.service new file mode 100644 index 0000000..d5d8249 --- /dev/null +++ b/home/private_dot_config/systemd/user/restic-prune.service @@ -0,0 +1,7 @@ +[Unit] +Description=Restic backup service (data pruning) + +[Service] +Type=oneshot +ExecStart=restic prune +EnvironmentFile=%h/.config/restic/othalan.env diff --git a/home/private_dot_config/systemd/user/restic-prune.timer b/home/private_dot_config/systemd/user/restic-prune.timer new file mode 100644 index 0000000..2898d26 --- /dev/null +++ b/home/private_dot_config/systemd/user/restic-prune.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Prune data from the restic repository monthly + +[Timer] +OnCalendar=monthly +Persistent=true + +[Install] +WantedBy=timers.target