Browse Source

new: [rsync-backup] use key commentary to store backup type

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
upd-docker
Valentin Lab 4 years ago
parent
commit
dfb2a6a7b5
  1. 21
      rsync-backup/hooks/install.d/60-install.sh

21
rsync-backup/hooks/install.d/60-install.sh

@ -4,16 +4,20 @@
set -eux
[ "${DOMAIN}" ] || {
[ -n "${DOMAIN}" ] || {
echo "Error: you must set \$DOMAIN prior to running this script." >&2
exit 1
}
[ "${BACKUP_SERVER}" ] || {
[ -n "${BACKUP_SERVER}" ] || {
echo "Error: you must set \$BACKUP_SERVER prior to running this script." >&2
exit 1
}
KEY_BACKUP_ID=${KEY_BACKUP_ID:-rsync}
KEY_COMMENTARY="$KEY_BACKUP_ID@$DOMAIN"
MIRROR_DIR_PATH="${MIRROR_DIR_PATH:-$PWD/resources/bin/mirror-dir}"
[ -e "$MIRROR_DIR_PATH" ] || {
echo "Error: you must set \$MIRROR_DIR_PATH or be the root of the charm to run this script." >&2
@ -35,8 +39,17 @@ getent passwd rsync >/dev/null ||
chown rsync:rsync /var/lib/rsync
## rsync ssh key creation
[ -e /var/lib/rsync/.ssh/id_rsa ] ||
su -c 'ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q -C rsync@'"$DOMAIN" - rsync
if [ -e /var/lib/rsync/.ssh/id_rsa.pub ]; then
## Mainly for update of old solution
content=$(cat /var/lib/rsync/.ssh/id_rsa.pub)
commentary=${content##* }
if [ "${commentary}" != "$KEY_COMMENTARY" ]; then
echo "Updating ssh key commentary from '${commentary}' to '$KEY_COMMENTARY'" >&2
sed -ri "s/ [^ ]+\$/ $KEY_COMMENTARY/" /var/lib/rsync/.ssh/id_rsa.pub
fi
else
su -c 'ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q -C '"$KEY_COMMENTARY" - rsync
fi
dest="$BACKUP_SERVER"
if [[ "$dest" == *"/"* ]]; then

Loading…
Cancel
Save