#!/bin/bash
# Copyright (C) 2018, Fork Sand, Inc.
# GPLv3
#
# This scriptlet collects the keys needed to restore a backup,
# should the host keys get lost.
# Store on an external secure vault.

set -x
BORG_KEYS_DIR="/root/borg-`hostname`-keys"

mv $BORG_KEYS_DIR $BORG_KEYS_DIR.bak
mkdir -p $BORG_KEYS_DIR
cp -a /root/.config/borg $BORG_KEYS_DIR/dot-config-borg
cp -a /root/.ssh/id_ed25519-borg-`hostname` $BORG_KEYS_DIR/dot-ssh-id_ed25519-borg-`hostname`
cp -a /root/.ssh/id_ed25519-borg-`hostname`.pub $BORG_KEYS_DIR/dot-ssh-id_ed25519-borg-`hostname`.pub

cd /root
tar jcf borg-`hostname`-keys.tar.bz2 borg-`hostname`-keys

# manually remove this
mv $BORG_KEYS_DIR $BORG_KEYS_DIR-done

echo "Keys backup: $BORG_KEYS_DIR.tar.bz2"

