|
|
@@ -72,38 +72,32 @@ setup_venv() |
|
|
|
pipenv install |
|
|
|
} |
|
|
|
|
|
|
|
# Create wrapper to execute borg |
|
|
|
create_borg_wrapper() |
|
|
|
# Create shell script with environment variables |
|
|
|
create_borg_vars() |
|
|
|
{ |
|
|
|
BORG=${BORG_DIR}/borg.sh |
|
|
|
VARS=${BORG_DIR}/vars.sh |
|
|
|
|
|
|
|
# These variables are used elsewhere in this script |
|
|
|
BORG_REPO="ssh://${BACKUP_USER}@${BACKUP_HOST}/./${BACKUP_REPO}" |
|
|
|
BORG=${BORG_DIR}/borg.sh |
|
|
|
SSH=$BORG_DIR/ssh |
|
|
|
|
|
|
|
cat >"$BORG" <<EOF |
|
|
|
#!/bin/sh |
|
|
|
|
|
|
|
cat >"$VARS" <<EOF |
|
|
|
export BACKUP_USER=${BACKUP_USER} |
|
|
|
export BACKUP_HOST=${BACKUP_HOST} |
|
|
|
export BACKUP_REPO=${BACKUP_REPO} |
|
|
|
export HOSTNAME=$(hostname) |
|
|
|
export BORG_REPO=${BORG_REPO} |
|
|
|
export BORG_HOST_ID=${HOSTID} |
|
|
|
export BORG_PASSCOMMAND="cat ${BORG_DIR}/passphrase" |
|
|
|
export BORG_HOST_ID=${HOSTID} |
|
|
|
export BORG_BASE_DIR=${BORG_DIR} |
|
|
|
export BORG_CACHE_DIR=${BORG_DIR}/cache |
|
|
|
export BORG_CONFIG_DIR=${BORG_DIR}/config |
|
|
|
if [ "\$1" = "--rw" ] ; then |
|
|
|
if [ "$BORG_RW_KEY_ADDED" != "1" ] ; then |
|
|
|
echo "=== Need SSH key passphrase. Check Bitwarden for:" |
|
|
|
echo "=== borg $(hostname) / read-write SSH key" |
|
|
|
fi |
|
|
|
export BORG_RSH="ssh -F $SSH/config -o BatchMode=no -i $SSH/id_ecdsa" |
|
|
|
shift |
|
|
|
else |
|
|
|
export BORG_RSH="ssh -F $SSH/config -i $SSH/id_ecdsa_appendonly" |
|
|
|
fi |
|
|
|
|
|
|
|
exec "${BORG_BIN}" "\$@" |
|
|
|
export BORG_DIR=${BORG_DIR} |
|
|
|
export SSH=${SSH} |
|
|
|
export BORG=${BORG} |
|
|
|
export BORG_BIN=${BORG_BIN} |
|
|
|
EOF |
|
|
|
chmod +x "$BORG" |
|
|
|
if ! "$BORG" -h >/dev/null ; then |
|
|
|
error "Can't run the new borg wrapper; does borg work?" |
|
|
|
error "Can't run the borg wrapper; does borg work?" |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
@@ -297,7 +291,7 @@ git_setup() |
|
|
|
fi |
|
|
|
|
|
|
|
log "Committing local changes to git" |
|
|
|
git add README.md borg-backup.service borg-backup.timer borg.sh |
|
|
|
git add README.md borg-backup.service borg-backup.timer vars.sh |
|
|
|
git commit -a -m "autocommit after initial setup on $(hostname)" |
|
|
|
} |
|
|
|
|
|
|
@@ -307,7 +301,7 @@ log " Backup server user: ${BACKUP_USER}" |
|
|
|
log " Repository path: ${BACKUP_REPO}" |
|
|
|
|
|
|
|
setup_venv |
|
|
|
create_borg_wrapper |
|
|
|
create_borg_vars |
|
|
|
generate_keys |
|
|
|
configure_ssh |
|
|
|
create_repo |
|
|
|