diff --git a/core/cli.py b/core/cli.py index 913796b..bf87d1b 100644 --- a/core/cli.py +++ b/core/cli.py @@ -31,6 +31,7 @@ class Command(Enum): TRAFFIC_STATUS = 'traffic.py' # won't be call directly (it's a python module) LIST_USERS = os.path.join(SCRIPT_DIR, 'hysteria2', 'list_users.sh') SERVER_INFO = os.path.join(SCRIPT_DIR, 'hysteria2', 'server_info.sh') + BACKUP_HYSTERIA = os.path.join(SCRIPT_DIR, 'hysteria2', 'backup.sh') INSTALL_TELEGRAMBOT = os.path.join(SCRIPT_DIR, 'telegrambot', 'runbot.sh') INSTALL_SINGBOX = os.path.join(SCRIPT_DIR, 'singbox', 'singbox_shell.sh') INSTALL_TCP_BRUTAL = os.path.join(SCRIPT_DIR, 'tcp-brutal', 'install.sh') @@ -224,6 +225,14 @@ def server_info(): output = run_cmd(['bash', Command.SERVER_INFO.value]) if output: print(output) + +@cli.command('backup-hysteria') +def backup_hysteria(): + try: + run_cmd(['bash', Command.BACKUP_HYSTERIA.value]) + except subprocess.CalledProcessError as e: + click.echo(f"Backup failed: {e.output.decode()}", err=True) + # endregion # region advanced menu diff --git a/core/scripts/hysteria2/backup.sh b/core/scripts/hysteria2/backup.sh new file mode 100644 index 0000000..199ea1a --- /dev/null +++ b/core/scripts/hysteria2/backup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +BACKUP_DIR="/opt/hysbackup" +BACKUP_FILE="$BACKUP_DIR/hysteria_backup_$(date +%Y%m%d_%H%M%S).zip" + +if [ ! -d "$BACKUP_DIR" ]; then + mkdir -p "$BACKUP_DIR" +fi + +FILES_TO_BACKUP=( + "/etc/hysteria/ca.key" + "/etc/hysteria/ca.crt" + "/etc/hysteria/users.json" + "/etc/hysteria/config.json" +) + +zip -j "$BACKUP_FILE" "${FILES_TO_BACKUP[@]}" >/dev/null + +if [ $? -eq 0 ]; then + echo "Backup successfully created" +else + echo "Backup failed!" +fi diff --git a/install.sh b/install.sh index c08d75a..cd8f518 100644 --- a/install.sh +++ b/install.sh @@ -10,7 +10,7 @@ if ! command -v jq &> /dev/null || ! command -v git &> /dev/null || ! command -v echo "${yellow}Necessary packages are not installed. Please wait while they are being installed..." sleep 3 echo - apt update && apt upgrade -y && apt install jq qrencode curl pwgen uuid-runtime python3 python3-pip python3-venv git bc -y + apt update && apt upgrade -y && apt install jq qrencode curl pwgen uuid-runtime python3 python3-pip python3-venv git bc zip -y fi git clone https://github.com/ReturnFI/Hysteria2 /etc/hysteria