Backup site to another server

Backup site to another server

As it is written inside of script, you can use this simple script below to backup site to another server, exclude parameters you don’t need, for example ssh keys.

#!/bin/bash
# Script to back up folder, for example website, to another server, for big sites like 10GB and more use tmux
# presumption is that port is changed to 3344 and ssh is using keys and tmux and rsync are installed
# change parameters, this is random written

# === CONFIGURATION ===
SOURCE_DIR=”/var/www/mywebsite”
DEST_USER=”root”
DEST_IP=”33.60.141.151″
DEST_PORT=”3344″
DEST_KEY=”/root/.ssh/id_ed25519″
DEST_DIR=”/var/backups/mybackup/”
LOG_FILE=”/root/rsync_backup_$(date +%F).log”

# —– Ensure we are inside tmux —–
if [[ -z “${TMUX:-}” ]]; then
echo “⚠️ Please run this script inside tmux:”
echo ” tmux new -s rsyncbackup”
exit 1
fi

# === Start TMUX if not inside one ===
if [ -z “$TMUX” ]; then
echo “🚨 Run this script inside tmux to avoid losing progress if disconnected.”
echo “👉 Run: tmux new -s rsyncbackup”
exit 1
fi

# —– Perform the rsync backup —–
echo “[*] Starting rsync …”
rsync -avz –progress \
-e “ssh -p ${DEST_PORT} -i ${DEST_KEY}” \
“${SOURCE_DIR}/” “${DEST_USER}@${DEST_IP}:${DEST_DIR}/” \
2>&1 | tee -a “${LOG_FILE}”

echo “[✓] Backup finished – log saved to ${LOG_FILE} and Files are now on: $DEST_IP:$DEST_DIR”