|
|
@ -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' |
|
|
|