Sample Header Ad - 728x90

Cannot use borgbackup script with sudo as requires ssh password

1 vote
1 answer
604 views
I am trying to use borg backup and am running into an issue with SSH. I am backing up some root files such as /var/www/html, therefore I require root permissions, so I need to run the backup script as root, but when I run it as root the SSH key doesn't seem to work, and as it's a script I'd like to run with cron it means I cant be entering the password each time. Note that the SSH keys work when I run the script from my user, but then the backup doesn't work as some of the file locations are permission denied. I am backing up to a storage box with Hetzner. My Script: #!/usr/bin/env bash LOG="/var/log/borg/backup.log" BACKUP_USER="XXXXXXX" REPOSITORY_DIR="backups/Node1" REPOSITORY="ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./${REPOSITORY_DIR}" exec > >(tee -i ${LOG}) exec 2>&1 echo "###### Backup started: $(date) ######" echo "Transfer files ..." BORG_PASSPHRASE='XXXXXXXXXX' borg create -v --stats \ $REPOSITORY::'{now:%Y-%m-%d_%H:%M}' \ /root \ /etc \ /var/www \ /home \ --exclude /dev \ --exclude /proc \ --exclude /sys \ --exclude /var/run \ --exclude /run \ --exclude /lost+found \ --exclude /mnt \ --exclude /var/lib/lxcfs echo "###### Backup ended: $(date) ######"
Asked by Deadaccount (21 rep)
Aug 4, 2022, 10:52 PM
Last activity: Aug 5, 2022, 01:16 PM