#!/bin/bash # # Purpose : Point restic at your backup in your Nextcloud files. Sourced by # system/backup and configure.d/20-backup.sh, and by you (in bash # or zsh) to look at or restore from a backup: # # source /backup-env.sh # restic snapshots # # To use another computer's backup, name its folder: # # source /backup-env.sh .backup- # # restic reaches Nextcloud over WebDAV through rclone. The Nextcloud app # password and the backup's passphrase are in your login keychain. This is # sourced by zsh too, so it uses no bash-only syntax. BACKUP_CONF="$HOME/Library/Application Support/Federated Connector/backup.conf" BACKUP_KEYCHAIN="federated-connector-backup" FC_TOOLS="$HOME/.local/share/federated-connector" PATH="$FC_TOOLS/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" export PATH # A secret from the keychain: nextcloud: (app password) or # passphrase:/ backup_secret() { security find-generic-password -s "$BACKUP_KEYCHAIN" -a "$1" -w 2> /dev/null } if [ -f "$BACKUP_CONF" ]; then . "$BACKUP_CONF" BACKUP_DIR="${1:-$BACKUP_DIR}" export RCLONE_WEBDAV_URL="$BACKUP_WEBDAV" # BACKUP_VENDOR is only set by the smoketest, whose stand-in for Nextcloud # is a plain WebDAV server export RCLONE_WEBDAV_VENDOR="${BACKUP_VENDOR:-nextcloud}" export RCLONE_WEBDAV_USER="$BACKUP_USER" RCLONE_WEBDAV_PASS="$(backup_secret "nextcloud:$BACKUP_WEBDAV" | rclone obscure - 2> /dev/null)" export RCLONE_WEBDAV_PASS export RESTIC_REPOSITORY="rclone::webdav:$BACKUP_DIR" # Without a passphrase in the keychain, e.g. for another computer's backup, # restic asks for it unset RESTIC_PASSWORD_COMMAND if [ -n "$(backup_secret "passphrase:$BACKUP_WEBDAV/$BACKUP_DIR")" ]; then export RESTIC_PASSWORD_COMMAND="security find-generic-password -s $BACKUP_KEYCHAIN -a passphrase:$BACKUP_WEBDAV/$BACKUP_DIR -w" fi else echo "Backups aren't set up. Run: configure backup" >&2 fi