Browse Source

new: [0km] add ``vps-install backup`` which handle all stage of backup

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
rc1
Valentin Lab 3 years ago
parent
commit
5901c4ff45
  1. 22
      README.org
  2. 103
      bin/0km

22
README.org

@ -745,6 +745,28 @@ export MYSQL_CONTAINER=mailcowdockerized_mysql-mailcow_1
=compose= à backupper.
- un serveur =mailcow= est un serveur faisant tourner l'installation =mailcow=.
***** Via la commande 0km sur un hôte admin
L'instruction suivante doit être executée sur un hôte ayant la commande
=0km= d'installée et les accès vers le VPS et un compte administration
du serveur d'archivage.
#+begin_src sh
0km vps-install backup myadmin@core-06.0k.io:10023 myvps.fr
#+end_src
Note: on peut spécifier autant de vps que l'on souhaite en fin de
ligne de commande. L'installation des vps se fera en parallèle et
vers le serveur d'archive spécifié en premier argument.
Note: cette commande peut-être executé plusieurs fois sur le même
hôte : si tout est déjà installé, cette commande n'aura pour seul
effet que de relancer une synchronisation vers le backup.
***** Via la commande vps sur le vps lui-même
A faire depuis le serveur compose ou mailcow:
#+begin_src sh

103
bin/0km

@ -234,6 +234,76 @@ vps_check() {
}
vps_install_backup() {
local vps="$1" admin server
vps_connection_check "$vps" </dev/null || return 1
read-0 admin server
if ! type=$(ssh:run "root@$vps" -- vps get-type); then
err "Could not get type."
return 1
fi
if ! out=$(ssh:run "root@$vps" -- vps install backup "$server" 2>&1); then
err "Command 'vps install backup $server' failed."
return 1
fi
already_present=
if e "$out" | grep "^II Entry for service .* is already present" >/dev/null 2>&1; then
already_present=1
info "Backup entry is already present in 'compose.yml' of '$vps'"
fi
out="${out%$'\n'}"
out="${out#*$'\n'}"
key="${out%\'*}"
key="${key##*\'}"
if ! [[ "$key" =~ ^"ssh-rsa "[a-zA-Z0-9/+]+" "[a-zA-Z0-9._-]+"@"[a-zA-Z0-9._-]+$ ]]; then
err "Unexpected output from 'vps install backup $server'. Can't find key."
echo "$out" | prefix " ${GRAY}|$NORMAL " >&2
echo " Extracted key:" >&2
echo "$key" | prefix " ${GRAY}|$NORMAL " >&2
return 1
fi
if [ "$type" == "compose" ] && [ -z "$already_present" ]; then
ssh:run "root@$vps" -- compose --debug up || {
err "Command 'compose --debug up' failed."
return 1
}
fi
dest="$server"
dest="${dest%/*}"
ssh_options=()
if [[ "$dest" == *":"* ]]; then
port="${dest##*:}"
dest="${dest%%:*}"
ssh_options=(-p "$port")
else
port=""
dest="${dest%%:*}"
fi
cmd=(ssh "${ssh_options[@]}" "$admin"@"$dest" ssh-key add "$key")
echo "${WHITE}Launching:${NORMAL} ${cmd[@]}"
"${cmd[@]}" || {
err "Failed add key to backup server '$dest'."
return 1
}
echo "${WHITE}Launching backup${NORMAL} from '$vps'"
ssh:run "root@$vps" -- vps backup || {
err "First backup failed to run."
return 1
}
echo "Backup is ${GREEN}up and running${NORMAL}."
}
vps_udpate() {
local vps="$1"
vps_connection_check "$vps" || return 1
@ -438,8 +508,39 @@ cmdline.spec::cmd:vps-check:run() {
}
cmdline.spec.gnu vps-update
cmdline.spec.gnu vps-install
cmdline.spec::cmd:vps-install:run() {
:
}
cmdline.spec.gnu backup
cmdline.spec:vps-install:cmd:backup:run() {
: :posarg: BACKUP_TARGET 'Backup target.
(ie: myadmin@backup.domain.org:10023/256)'
: :posarg: [VPS...] 'Target host(s) to check'
if [ "${#VPS[@]}" == 0 ]; then
warn "VPS list provided in command line is empty. Nothing will be done."
return 0
fi
if ! [[ "$BACKUP_TARGET" == *"@"* ]]; then
err "Missing admin account identifier in backup target."
echo " Have you forgottent to specify an account, ie 'myadmin@<MYBACKUP_SERVER>' ?)"
return 1
fi
admin=${BACKUP_TARGET%%@*}
server=${BACKUP_TARGET#*@}
p0 "$admin" "$server" |
vps_mux vps_install_backup "${VPS[@]}"
}
cmdline.spec.gnu vps-update
cmdline.spec::cmd:vps-update:run() {
: :posarg: [VPS...] 'Target host to check'

Loading…
Cancel
Save