this script covers the following:
/root
- docker compose stack, .ssh config
/etc/openpanel/
- contains all configuration files for openpanel, openadmin and other services
/usr/local/mail/openmail/
- if enterprise editon, holds mailserver configuration and email accounts
root_mysql
docker volume - holds mysql database with: users, plans, domains, sites, sessions..
/etc/cron.d/openpanel
- crons used ny the system (OpenAdmin > Advanced > System Cron Jobs)
This backup does NOT have any user data as containers, limits, websites, ports.. those are out of the scope of this backup.
This simple script will backup those files, enforce a 3-min timeout, and prevent multiple simultaneous runs. Use it to quickly backup openpanel configuration before performing major panel update or system/kernel update.
#!/bin/bash
set -euo pipefail
LOCK_FILE="/var/lock/openpanel-backup.lock"
DEFAULT_TIMEOUT=180 # 3 minutes
if [ -z "${OPENPANEL_BACKUP_TIMEOUT:-}" ]; then
export OPENPANEL_BACKUP_TIMEOUT=1
exec timeout "${1:-$DEFAULT_TIMEOUT}" "$0" "${@:2}"
fi
exec 200>"$LOCK_FILE"
flock -n 200 || { echo "⚠️ Backup already running. Exiting."; exit 1; }
BACKUP_DIR="${2:-/openpanel_backups}"
mkdir -p "$BACKUP_DIR"
DATE=$(date +%F_%H-%M-%S)
echo "🚀 Starting OpenPanel configuration backup: $DATE"
echo
SUCCESS=true
run_backup() {
local desc="$1"
shift
echo "📦 Backing up $desc..."
if "$@"; then
echo "[ OK. ] $desc completed."
else
echo "[ X ] $desc FAILED!"
SUCCESS=false
fi
echo
}
if [ -d /root ]; then
run_backup "openpanel stack" \
tar czf "$BACKUP_DIR/root_$DATE.tar.gz" -C /root
fi
if docker volume inspect root_mysql >/dev/null 2>&1; then
run_backup "MySQL Docker volume 'root_mysql'" \
docker run --rm \
-v root_mysql:/volume \
-v "$BACKUP_DIR":/backup \
alpine \
tar czf /backup/root_mysql_"$DATE".tar.gz -C /volume .
fi
if [ -d /etc/openpanel ]; then
run_backup "OpenPanel configuration" \
tar czf "$BACKUP_DIR/openpanel_config_$DATE.tar.gz" -C /etc openpanel
fi
if [ -d /usr/local/mail/openmail ]; then
run_backup "mailserver data" \
tar czf "$BACKUP_DIR/mailserver_$DATE.tar.gz" -C /usr/local/mail openmail
fi
if [ -f /etc/cron.d/openpanel ]; then
run_backup "OpenAdmin crons" \
tar czf "$BACKUP_DIR/crons_$DATE.tar.gz" -C /etc/cron.d openpanel
fi
if $SUCCESS; then
echo "🎉 Configuration backups completed successfully!"
else
echo "⚠️ Some backups failed! Please check the log above."
exit 1
fi