diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 index 52a2880..48b87b0 100644 --- a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 @@ -5,7 +5,6 @@ Description=Monthly restic check of the Litecoin wallet backup repository Type=oneshot Environment=RESTIC_REPOSITORY={{ litecoin_backup_repository }} Environment=RESTIC_PASSWORD_FILE={{ litecoin_backup_password_file }} -Environment=HOME={{ litecoin_backup_env_dir }} Environment=SSH_AUTH_SOCK= -ExecStart=/usr/bin/restic check --read-data-subset=5% +ExecStart=/usr/bin/restic -o sftp.command="ssh -i {{ litecoin_backup_ssh_key }} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile={{ litecoin_backup_known_hosts }}" check --read-data-subset=5% Nice=10 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 index 55fbb5a..28ab5c1 100644 --- a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 @@ -5,7 +5,7 @@ After=litecoind.service [Service] Type=oneshot ExecStart={{ litecoin_backup_script }} -# SSH key for the restic sftp target, root-only. -Environment=HOME={{ litecoin_backup_env_dir }} +# Runs as root; the script passes the restic SSH key and known_hosts +# explicitly via restic's sftp.command (ssh ignores $HOME for ~). Environment=SSH_AUTH_SOCK= Nice=10 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 index 4c0a9db..86b37ee 100644 --- a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 @@ -10,6 +10,10 @@ set -Eeuo pipefail export RESTIC_REPOSITORY="{{ litecoin_backup_repository }}" export RESTIC_PASSWORD_FILE="{{ litecoin_backup_password_file }}" +# ssh resolves ~ from the passwd entry, not from $HOME, so the restic sftp +# backend gets the key and known_hosts explicitly via sftp.command. +SFTP_COMMAND="ssh -i {{ litecoin_backup_ssh_key }} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile={{ litecoin_backup_known_hosts }}" + backup_dir="{{ litecoin_backup_wallet_dir }}" today="$(date +%F)" @@ -18,9 +22,11 @@ today="$(date +%F)" backupwallet "${backup_dir}/wallet-${today}" /usr/bin/restic -r "$RESTIC_REPOSITORY" \ + -o "sftp.command=$SFTP_COMMAND" \ --password-file "$RESTIC_PASSWORD_FILE" \ backup "$backup_dir" /usr/bin/restic -r "$RESTIC_REPOSITORY" \ + -o "sftp.command=$SFTP_COMMAND" \ --password-file "$RESTIC_PASSWORD_FILE" \ forget --keep-daily {{ litecoin_backup_keep_daily }} --prune