This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Are Bosch Green Laser Levels the Best Price Bargains?
#2
RE: Backup didn’t work
The original backup module is still buggy, so I'd recommend a script as a replacement.

Code:
#!/bin/bash
renice 19 -p $$
# Backup all Sentora accounts / replacing the php hook function.
# Should be run in cron job daily when server not under load
# with lower priority. Will generate one file per database
# prefixed with db_+name + time stamp and a html_ file that
# contain all public_html folder then also clear ALL backup
# older than clearday var.
panelroot="/var/sentora/hostdata"
date=$(date +"%d-%b-%Y_%H_%M")
clearday=20
#delete
backups older than XX days apply to all zip files
echo "Backup starting"
mysqlpassword=$(cat /etc/sentora/panel/cnf/db.php | grep "pass =" | sed -s "s|.*pass \= '\(.*\)';.*|\1|")
#enable
logging
logfile="/root/backup_last.log"
oldlogfile="/root/backup_old.log"
errorlogfile="/root/backup_error.log"
touch $errorlogfile
exec > >(tee $logfile)
exec 2>&1
rm -rf old_$logfile
mv $logfile $oldlogfile
echo "Starting backup $(date +"%d-%b-%Y %H:%M")">> $logfile

# Function function_backupdb_execute
# Dump mysql DB and compress it into backups folder
# $1 = user
# $2 = password
# $3 = host ( could remove host but can work as remote backup too! )
# $4 = database name to backup
# $5 = path
function_backup_db_execute() {
    backupfolder="$5/backups"
    mkdir -p $backupfolder
    mysqldump --user=$1 --password=$2 --host=$3 $4 > $backupfolder/$4_db_$date.sql
    zip -r $backupfolder/$4_db_$date.zip $backupfolder/$4_db_$date.sql
    rm -f $backupfolder/$4_db_$date.sql
}
# Function backup public_html folder zip
function_backup_html() {
    echo "html path backup now: $1/public_html"
    zip -r $panelroot/$1/backups/$1_html_$1_$date.zip $panelroot/$1/public_html/*
}
function_backup_clear() {
    # Delete files older than 45 days
    find $1/$2_*.zip -mtime +$clearday -exec rm -f {} \;
    echo "Removing old backups in $1 user $2"
}

# Function backup DB get list of DB then call DB dump
function_backup_db() {
    echo "user ID to backup : $1"
    mysql sentora_core -u root -p$mysqlpassword -e "SELECT my_name_vc FROM x_mysql_databases WHERE my_acc_fk='$1' AND my_deleted_ts IS NULL;;"| while read my_name_vc; do
    if [ ! "$my_name_vc" == "my_name_vc" ]; then
        echo "database to backup $my_name_vc"
        function_backup_db_execute root $mysqlpassword localhost $my_name_vc $2
    fi
done
}

# Get all users from mySQL DB
mysql sentora_core -u root -p$mysqlpassword -e "SELECT ac_id_pk, ac_user_vc, CONCAT('/var/sentora/hostdata/' , ac_user_vc) as ac_user_path,  CONCAT( CONCAT('/var/sentora/hostdata/' , ac_user_vc),'/public_html') as ac_user_path_tobackup FROM x_accounts WHERE ac_deleted_ts IS NULL and ac_enabled_in = 1 ;" | while read ac_id_pk ac_user_vc ac_user_path guid ac_user_path_tobackup; do
# Always skip first line returned by mysql...
if [ ! "$ac_user_path" == "ac_user_path" ]; then
    # if [  "$ac_user_vc" == "zadmin" ]; then # test working only for zadmin......
    echo "Path: $ac_user_path user to backup"
    function_backup_html $ac_user_vc >> $logfile
    function_backup_db $ac_id_pk $ac_user_path >> $logfile
    function_backup_clear "$ac_user_path/backups" $ac_user_vc >> $logfile
fi
done
echo "Finished backup $(date +"%d-%b-%Y %H:%M")">> $logfile
echo "All backup actions logged in $logfile and errors in $errorlogfile"

With root access, add it to a folder with a name of your choice inside the Root folder. Then crontab -e and add the full path to the script there.
Example in crontab -e: 15 3 * * 4 /root/backup/back.sh
This makes crontab run the script at 03:15 every Thursday. Adjust the time so it fits your timezone.
Only thing needed to edit in the script is the clearday line.


p.s. The
Code:
renice 19 -p $$
is something I added myself so the script doesn't choke the server with 100% cpu usage as I have some big files on some of my sites.

p.s.s. remember to fully disable the original backup module from sentora panel or else it may be running in the background and end up filling your server with backup files until there is no storage space left.

Source of script:
http://forums.sentora.org/showthread.php...97#pid1997
Reply
Thanks given by:


Messages In This Thread
RE: Backup didn’t work - by iraqiboy90 - 10-27-2020, 11:53 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)