libretime/easypanel/code/tools/restore-config.sh
Cesar Jhoanny Mendivil Rubio 697b7cc288
Some checks are pending
Container / meta (analyzer) (push) Waiting to run
Container / meta (api) (push) Waiting to run
Container / meta (legacy) (push) Waiting to run
Container / meta (nginx) (push) Waiting to run
Container / meta (playout) (push) Waiting to run
Container / meta (worker) (push) Waiting to run
Container / build (push) Blocked by required conditions
Project / pre-commit (push) Waiting to run
Project / test-tools (push) Waiting to run
Release-Please / release-please (push) Waiting to run
feat(easypanel): actualizar configuración y scripts de EasyPanel, incluyendo mejoras en la generación de contraseñas, sincronización de herramientas y gestión de configuraciones
2025-10-01 17:41:20 -07:00

103 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env sh
# restore-config.sh
# Lista y restaura backups creados por start.sh (config.local.yml.bak.YYYYMMDDHHMMSS)
set -e
WORKDIR="$(pwd)"
BACKUP_GLOB="$WORKDIR/config.local.yml.bak.*"
DEST="$WORKDIR/config.local.yml"
usage() {
cat <<EOF
Usage: $0 [--list] [--latest] [--restore <file>] [--yes]
Options:
--list List available backup files
--latest Show the latest backup file (implies --list)
--restore FILE Restore the specified backup into config.local.yml
--yes Skip confirmation when restoring
Examples:
$0 --list
$0 --latest
$0 --restore ./config.local.yml.bak.20251001102251
$0 --restore latest --yes
EOF
}
list_backups() {
ls -1 $BACKUP_GLOB 2>/dev/null | sort || true
}
latest_backup() {
# sort by name (timestamp suffix) and pick last
ls -1 $BACKUP_GLOB 2>/dev/null | sort | tail -n 1 || true
}
if [ "$#" -eq 0 ]; then
usage
exit 0
fi
FORCE=0
MODE=""
TARGET=""
while [ "$#" -gt 0 ]; do
case "$1" in
--list)
MODE=list; shift ;;
--latest)
MODE=latest; shift ;;
--restore)
MODE=restore; TARGET="$2"; shift 2 ;;
--yes)
FORCE=1; shift ;;
-h|--help)
usage; exit 0 ;;
*)
echo "Unknown arg: $1" >&2; usage; exit 1 ;;
esac
done
case "$MODE" in
list)
echo "Backups:";
list_backups;
exit 0
;;
latest)
echo "Latest backup:";
latest_backup;
exit 0
;;
restore)
if [ "$TARGET" = "latest" ] || [ -z "$TARGET" ]; then
TARGET=$(latest_backup)
fi
if [ -z "$TARGET" ] || [ ! -f "$TARGET" ]; then
echo "No backup found to restore: $TARGET" >&2
exit 1
fi
echo "About to restore backup: $TARGET -> $DEST"
if [ "$FORCE" -ne 1 ]; then
printf "Continue and overwrite %s? [y/N]: " "$DEST"
read ans || true
case "$ans" in
y|Y|yes|YES)
;;
*)
echo "Aborted."; exit 1 ;;
esac
fi
cp "$TARGET" "$DEST"
echo "Restored $TARGET -> $DEST"
exit 0
;;
*)
usage; exit 1 ;;
esac