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.

Fixing backup module
#14
RE: Fixing backup module
(09-17-2014, 05:19 AM)Me.B Wrote: For me shell is more efficient. No time out risk, less overhead under php.

Hi!
I have modified your script to obtain:
-backup for only one domain
-backup for only one database
-no junk path in compressed files
-.htaccess included in compressed files

I did this because i am hosting more than one domain in my account, but i am working only in one domain.
So i want the backup to be made for that domain only.

It would be nice to have in the Sentora backup module these options...

ALL CREDITS FOR THE SCRIPT GOES TO "Me.B" !!!
Also, THANK YOU SENTORA DEVS for a great hosting software!

Obs:
-the code is now messed up,and some variables may be redundant, but it's working
Setup:
-put the code where you want
-fill with your datas:
fldname="folder_to_be_backed_up"
dbname="database_to_be_backed_up"
clntname="your_hosting_user"

-chmod to script so you can run it:
chmod u+x /path/to/file/script.sh

-remove the break lines if there are any:
sed -i 's/\r//' /path/to/file/script.sh

-run the script
./script.sh

Code:
#!/bin/bash
fldname="folder_to_be_backed_up"
dbname="database_to_be_backed_up"
clntname="your_hosting_user"
panelroot="/var/sentora/hostdata"
date=$(date +"%d-%b-%Y_%H_%M")
clearday=45
#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|")
logfile="backup_last.log"
oldlogfile="backup_old.log"
errorlogfile="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_backup_db_execute() {
    backupfolder="$5/backups"
    mkdir -p $backupfolder
    mysqldump --user=$1 --password=$2 --host=$3 $4 > $backupfolder/$4_db_$date.sql
    cd $backupfolder
    zip -r $backupfolder/$4_db_$date.zip $4_db_$date.sql
    rm -f $backupfolder/$4_db_$date.sql
}
function_backup_html() {
       cd /root/
    echo "html path backup now: $1/public_html/$2"
       cd $panelroot/$1/public_html/$2
       zip -r $panelroot/$1/backups/$1_$2_files_$3.zip ./
}
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() {
    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" == $dbname ]; then
        echo "database to backup $my_name_vc"
        function_backup_db_execute root $mysqlpassword localhost $my_name_vc $2
    fi
done
}
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
if [  "$ac_user_vc" == $clntname ]; then
    echo "Backup: User: $clntname Folder: $fldname Database: $dbname"
    function_backup_html $ac_user_vc $fldname $date >> $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"
Reply
Thanks given by:


Messages In This Thread
Fixing backup module - by Me.B - 08-22-2014, 08:29 PM
RE: Fixing backup module - by Me.B - 09-16-2014, 07:02 AM
RE: Fixing backup module - by TGates - 09-16-2014, 08:00 AM
RE: Fixing backup module - by Me.B - 09-16-2014, 05:22 PM
RE: Fixing backup module - by Me.B - 09-16-2014, 05:50 PM
RE: Fixing backup module - by Me.B - 09-16-2014, 07:00 PM
RE: Fixing backup module - by jacobg830 - 09-17-2014, 05:13 AM
RE: Fixing backup module - by Me.B - 09-17-2014, 05:19 AM
RE: Fixing backup module - by maleabil - 04-06-2016, 07:09 PM
RE: Fixing backup module - by webnetvn - 09-18-2014, 08:49 AM
RE: Fixing backup module - by Me.B - 04-06-2016, 07:49 PM
RE: Fixing backup module - by betatester3.0 - 09-13-2017, 12:31 AM
RE: Fixing backup module - by Me.B - 09-13-2017, 12:40 AM
RE: Fixing backup module - by betatester3.0 - 09-13-2017, 01:21 AM
RE: Fixing backup module - by TGates - 09-13-2017, 03:45 AM
RE: Backup bug - by jacobg830 - 08-23-2014, 02:40 AM
RE: Backup bug - by kandrews - 09-02-2014, 05:58 AM
Fixing backup module - by Me.B - 09-12-2014, 12:32 AM
RE: Backup bug - by Me.B - 09-16-2014, 02:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Suggestion : Backup Import/Export patthe 1 6 ,010 11-25-2016, 02:49 PM
Last Post: Bobses
Client / Reseller Migration Module obrienj619 1 6 ,473 08-14-2016, 09:15 PM
Last Post: Me.B
Add time to Sentora Backup Config clu55ter 13 41 ,638 04-27-2016, 07:10 PM
Last Post: johnny09

Forum Jump:


Users browsing this thread: 4 Guest(s)