HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux newsites.squeezer-software.com 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/backup_data.sh
#!/bin/bash

############
# Settings #
############

# mysql parameters
MYSQL_USER="root"
MYSQL_PASSWORD="21YC#rIbzS"
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
BACKUP_LOCATION="/home/backups/mysql/"
BACKUP_SQLDIR=$BACKUP_LOCATION$(date +%Y-%m-%d_%H-%M)
EXCLUDE_DBS="(Database|information_schema|phpmyadmin|mysql|performance_schema)"
EXCLUDE_EGX="(MEMORY|ARCHIVE)"
GZIP_ENABLED=1

##############
# THE SCRIPT #
##############

echo "sophisticated dump of mysql databases"
echo "destination: $BACKUP_SQLDIR"
echo "ignore these databases: $EXCLUDE_DBS"
echo "ignore these engines: $EXCLUDE_EGX"
echo "gzipping: $GZIP_ENABLED"

#returns list of ignired tables
ignoredtables () {
   local IGNORES
   TABLES=`$MYSQL --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "USE $1; SHOW TABLE STATUS;"  | grep -E $EXCLUDE_EGX | awk '{print $1}'`
   for CURRENT_TB in $TABLES; do
       IGNORES="$IGNORES --ignore-table=$1.$CURRENT_TB"
   done
   echo $IGNORES
}

if [ ! -d "$BACKUP_SQLDIR" ]; then
    echo "make dir: "$BACKUP_SQLDIR
    mkdir -p $BACKUP_SQLDIR
fi

# get a list of databases
DATABASES=`$MYSQL --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev $EXCLUDE_DBS`

# dump each database in turn
echo "dumping databases..."
TIME_SPENT=`date +%s`
OVERAL_SPENT=`date +%s`
for CURRENT_DB in $DATABASES; do
    echo $CURRENT_DB
    IGNORED_TABLES=`ignoredtables $CURRENT_DB`
    if [ $GZIP_ENABLED == 1 ]; then
        $MYSQLDUMP --force --opt --routines --user=$MYSQL_USER --password=$MYSQL_PASSWORD $IGNORED_TABLES $CURRENT_DB | gzip > "$BACKUP_SQLDIR/$CURRENT_DB.sql.gz"
    else
        $MYSQLDUMP --force --opt --routines --user=$mYSQL_USER --password=$MYSQL_PASSWORD $IGNORED_TABLES $CURRENT_DB > "$BACKUP_SQLDIR/$CURRENT_DB.sql"
    fi
    TIME_SPENT=$((`date +%s` - $TIME_SPENT))
    echo "spent: "$TIME_SPENT"s         overal: "$((`date +%s` - $OVERAL_SPENT))"s"
    TIME_SPENT=`date +%s`
done

# removes previous backup older then 7 days
find $BACKUP_LOCATION -mtime +7 -type d -exec rm -Rv {} \;

echo "[done]"