Files
2026-01-20 17:51:59 -08:00

76 lines
2.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
###CONFIGURATION ###
REMOTE_USER="crowetic"
REMOTE_HOST="devnet-nodes.qortal.link"
REMOTE_PORT=22225
REMOTE_BASE_DIR="/qortal" # <–– adjust!
ARCHIVE_NAME="db-Devnet-$(date +%Y%m%d_%H%M%S).7z"
REMOTE_ARCHIVE_PATH="${REMOTE_BASE_DIR}/${ARCHIVE_NAME}"
REMOTE_JAR_PATH="${REMOTE_BASE_DIR}/qortal.jar"
LOCAL_SYNC_DIR="/mnt/4TB-WDB/DATA/QortalCloud/DevNet"
################################################
log() { echo "[$(date +'%H:%M:%S')] $*"; }
log "Starting remote backup on ${REMOTE_HOST}..."
ssh -p "${REMOTE_PORT}" "${REMOTE_USER}@${REMOTE_HOST}" bash -l <<EOF
set -euxo pipefail
cd "${REMOTE_BASE_DIR}"
echo "→ Checking for 7z…"
command -v 7z || { echo "ERROR: Install p7zip-full" >&2; exit 1; }
echo "→ Stopping Qortal…"
if [[ -x ./stop.sh ]]; then
set +e
./stop.sh
RET=\$?
set -e
if (( RET != 0 )); then
echo "⚠️ stop.sh exited with code \$RET; continuing anyway."
fi
else
echo "⚠️ stop.sh not found or not executable; skipping stop."
fi
echo "→ Archiving db/ → ${ARCHIVE_NAME}…"
[[ -d db ]] || { echo "ERROR: db/ folder not found" >&2; exit 1; }
7z a "${ARCHIVE_NAME}" db
echo "→ Restarting Qortal…"
if [[ -x ./start.sh ]]; then
./start.sh
else
echo "⚠️ start.sh not found or not executable; skipping start."
fi
echo "→ Remote work complete."
EOF
log "Rsyncing archive down…"
rsync -ravPz \
-e "ssh -p ${REMOTE_PORT}" \
"${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_ARCHIVE_PATH}" \
"${LOCAL_SYNC_DIR}/"
rsync -ravPs \
-e "ssh -p ${REMOTE_PORT}" \
"${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_JAR_PATH}" \
"${LOCAL_SYNC_DIR}/"
log "Removing remote archive…"
ssh -p "${REMOTE_PORT}" "${REMOTE_USER}@${REMOTE_HOST}" rm -f "${REMOTE_ARCHIVE_PATH}"
log "Pruning local archives older than 2 days…"
find "${LOCAL_SYNC_DIR}" -maxdepth 1 -name 'db-Devnet-*.7z' -mtime +2 -delete
log "✔ Backup complete."