Archived
1
0
Fork 0
This repository has been archived on 2023-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/install/borg.sh

49 lines
1.8 KiB
Bash
Raw Normal View History

2022-05-10 01:25:47 +02:00
#!/bin/bash
set -e
# Packages
sudo apt update
sudo apt install -y borgbackup
# Backup script - not symlinked to avoid potential privilege escalation
sudo cp borg/backup.sh /usr/local/sbin/backup.sh
sudo chown root:root /usr/local/sbin/backup.sh
sudo chmod 744 /usr/local/sbin/backup.sh
# Passphrase
if [ ! -f /usr/local/etc/borg/passphrase.key ]; then
2022-05-10 01:25:49 +02:00
sudo mkdir --parents --mode=700 /usr/local/etc/borg/
2022-05-10 01:25:47 +02:00
echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
echo '@@ PLEASE BACKUP BORG PASSPHRASE: @@'
pwgen 32 1 | sudo tee /usr/local/etc/borg/passphrase.key
echo '@@ (/usr/local/etc/borg/passphrase.key) @@'
echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
read -p 'Press any key to continue..'
sudo chmod 600 /usr/local/etc/borg/passphrase.key
fi
# Systemd service and timer - not symlinked to avoid potential privilege escalation
sudo cp borg/borg-daily.service /etc/systemd/system/
sudo cp borg/borg-daily.timer /etc/systemd/system/
sudo chown root:root /etc/systemd/system/borg-daily.service /etc/systemd/system/borg-daily.timer
sudo systemctl enable borg-daily.timer
# SSH
ssh-keyscan -t ed25519 -p 222 sigma.caspervk.net | sudo tee /root/.ssh/known_hosts # add backup server to known_hosts
sudo ssh-keygen -t ed25519 # generate key for the root user
2022-05-10 01:25:49 +02:00
echo "Please add the following to ~borg/.ssh/authorized_keys on the server:"
2022-05-10 01:25:47 +02:00
echo "command=\"mkdir -p ~/repos/$(hostname); cd ~/repos/$(hostname); borg serve --append-only --restrict-to-path ~/repos/$(hostname)\",restrict $(sudo cat /root/.ssh/id_ed25519.pub)"
2022-05-10 01:25:49 +02:00
read -p 'Press any key when done to test the connection.. (should return "PTY allocation request failed on channel 0")'
sudo ssh borg@sigma.caspervk.net -p 222
2022-05-10 01:25:47 +02:00
# To setup the server:
# sudo apt install borgbackup
# sudo adduser --disabled-password borg
# sudo su borg
# cd ~
2022-05-10 01:25:49 +02:00
# mkdir --mode=700 repos/