Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 46 additions & 32 deletions marzban.sh
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ backup_command() {
local backup_file="$backup_dir/backup_$timestamp.tar.gz"
local error_messages=()
local log_file="/var/log/marzban_backup_error.log"

# Очистка лога перед началом нового бэкапа
> "$log_file"
echo "Backup Log - $(date)" > "$log_file"

Expand Down Expand Up @@ -524,7 +526,22 @@ backup_command() {
send_backup_error_to_telegram "${error_messages[*]}" "$log_file"
exit 1
fi


if [ -f "$ENV_FILE" ]; then
MYSQL_ROOT_PASSWORD=$(grep -E '^MYSQL_ROOT_PASSWORD=' "$ENV_FILE" | cut -d '=' -f2 | xargs)
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
error_messages+=("MYSQL_ROOT_PASSWORD not set in $ENV_FILE.")
echo "MYSQL_ROOT_PASSWORD not set in $ENV_FILE." >> "$log_file"
send_backup_error_to_telegram "${error_messages[*]}" "$log_file"
exit 1
fi
else
error_messages+=("Environment file ($ENV_FILE) not found.")
echo "Environment file ($ENV_FILE) not found." >> "$log_file"
send_backup_error_to_telegram "${error_messages[*]}" "$log_file"
exit 1
fi

local db_type=""
local sqlite_file=""
if grep -q "image: mariadb" "$COMPOSE_FILE"; then
Expand All @@ -548,12 +565,12 @@ backup_command() {
echo "Database detected: $db_type" >> "$log_file"
case $db_type in
mariadb)
if ! docker exec "$container_name" mariadb-dump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases > "$temp_dir/db_backup.sql" 2>>"$log_file"; then
if ! docker exec "$container_name" mariadb-dump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases --events --triggers > "$temp_dir/db_backup.sql" 2>>"$log_file"; then
error_messages+=("MariaDB dump failed.")
fi
;;
mysql)
if ! docker exec "$container_name" mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases > "$temp_dir/db_backup.sql" 2>>"$log_file"; then
if ! docker exec "$container_name" mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases --events --triggers > "$temp_dir/db_backup.sql" 2>>"$log_file"; then
error_messages+=("MySQL dump failed.")
fi
;;
Expand Down Expand Up @@ -589,7 +606,6 @@ backup_command() {
}



get_xray_core() {
identify_the_operating_system_and_architecture
clear
Expand Down Expand Up @@ -746,20 +762,19 @@ services:
MYSQL_USER: \${MYSQL_USER}
MYSQL_PASSWORD: \${MYSQL_PASSWORD}
command:
- --bind-address=127.0.0.1 # Restricts access to localhost for increased security
- --character_set_server=utf8mb4 # Sets UTF-8 character set for full Unicode support
- --collation_server=utf8mb4_unicode_ci # Defines collation for Unicode
- --host-cache-size=0 # Disables host cache to prevent DNS issues
- --innodb-open-files=1024 # Sets the limit for InnoDB open files
- --innodb-buffer-pool-size=256M # Allocates buffer pool size for InnoDB
- --binlog_expire_logs_seconds=1209600 # Sets binary log expiration to 14 days (2 weeks)
- --innodb-log-file-size=64M # Sets InnoDB log file size to balance log retention and performance
- --innodb-log-files-in-group=2 # Uses two log files to balance recovery and disk I/O
- --innodb-doublewrite=0 # Disables doublewrite buffer (reduces disk I/O; may increase data loss risk)
- --general_log=0 # Disables general query log to reduce disk usage
- --slow_query_log=1 # Enables slow query log for identifying performance issues
- --slow_query_log_file=/var/lib/mysql/slow.log # Logs slow queries for troubleshooting
- --long_query_time=2 # Defines slow query threshold as 2 seconds
- --bind-address=127.0.0.1
- --character_set_server=utf8mb4
- --collation_server=utf8mb4_unicode_ci
- --host-cache-size=0
- --innodb-open-files=1024
- --innodb-buffer-pool-size=256M
- --binlog_expire_logs_seconds=86400
- --innodb-log-file-size=64M
- --innodb-log-files-in-group=2
- --innodb-doublewrite=0
- --general_log=0
- --slow_query_log=0
- --log_error=/dev/null
volumes:
- /var/lib/marzban/mysql:/var/lib/mysql
healthcheck:
Expand Down Expand Up @@ -835,31 +850,30 @@ services:
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: \${MYSQL_DATABASE}
MYSQL_USER: \${MYSQL_USER}
MYSQL_PASSWORD: \${MYSQL_PASSWORD}
MYSQL_PASSWORD: \${MYSQL_PASSWORD}
command:
- --mysqlx=OFF # Disables MySQL X Plugin to save resources if X Protocol isn't used
- --mysqlx=OFF # Disables MySQL X Plugin to save resources if not needed
- --bind-address=127.0.0.1 # Restricts access to localhost for increased security
- --character_set_server=utf8mb4 # Sets UTF-8 character set for full Unicode support
- --collation_server=utf8mb4_unicode_ci # Defines collation for Unicode
- --log-bin=mysql-bin # Enables binary logging for point-in-time recovery
- --binlog_expire_logs_seconds=1209600 # Sets binary log expiration to 14 days
- --binlog_expire_logs_seconds=86400 # Sets binary log expiration to 1 day (24 hours)
- --host-cache-size=0 # Disables host cache to prevent DNS issues
- --innodb-open-files=1024 # Sets the limit for InnoDB open files
- --innodb-buffer-pool-size=256M # Allocates buffer pool size for InnoDB
- --innodb-log-file-size=64M # Sets InnoDB log file size to balance log retention and performance
- --innodb-buffer-pool-size=256M # Allocates buffer pool size for InnoDB performance
- --innodb-log-file-size=64M # Sets InnoDB log file size for log retention and performance
- --innodb-log-files-in-group=2 # Uses two log files to balance recovery and disk I/O
- --general_log=0 # Disables general query log for lower disk usage
- --slow_query_log=1 # Enables slow query log for performance analysis
- --slow_query_log_file=/var/lib/mysql/slow.log # Logs slow queries for troubleshooting
- --long_query_time=2 # Defines slow query threshold as 2 seconds
- --general_log=0 # Disables general query log to reduce disk usage
- --slow_query_log=0 # Disables slow query log to prevent disk growth
- --log-error=/dev/null # Redirects error logs to /dev/null, effectively disabling them
volumes:
- /var/lib/marzban/mysql:/var/lib/mysql
- /var/lib/marzban/mysql:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "marzban", "--password=\${MYSQL_PASSWORD}"]
start_period: 5s
interval: 5s
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "marzban", "--password=${MYSQL_PASSWORD}"] # Checks MySQL availability
start_period: 5s
interval: 5s
timeout: 5s
retries: 55
retries: 55

EOF
echo "----------------------------"
Expand Down