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
#11
RE: Fixing backup module
Great to see you are sorting out the backup module Smile Any reason for using bash scripts over PHP? Surely PHP makes for far more cross-platform code - remember Sentora/ZPanel is designed to with all UNIX operating systems and not just Linux. I think it would make more sense to carry on using PHP where possible to maintain compatibility.

Your script is broken on my FreeBSD Sad but works on Ubuntu Smile
Before posting, update your profile with your OS, Sentora version and server type!

Reply
Thanks given by:
#12
RE: Fixing backup module
why broken on freebsd? Didn't target it.

For me shell is more efficient. No time out risk, less overhead under php. Also I can do the same for windows! ( we could too for freebsd ). Notice I think more about wiping out zsudo and tightening the security to lock down totally sentora.

And also I was preparing to work on installers so I wanted a quick fix. It would easily as I said scale to per user settings. Love how it hack mysql into bash.

I can imagine later a restore script that could be triggered by users too... Imagine you can restore the backup in 2 clicks. It's not so hard to do.

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Coldfusion Freelance

10$ free to start your VPS

Reply
Thanks given by:
#13
RE: Fixing backup module
Ill be happy to test this guy out for you too me.b give me day or so and ill get back to you with results. this seems more viable as a migration system as well taking it out of php makes it so average joes cant use it considering it backs up databases etc (i suppose we could do this with permissions in the panel too but oh well). Ill be using it to attempt a migration from 12.04 to 14.04 D: hopefully it wont have the number of issues ive been experiencing doing it by hand.

Perhaps we can integrate this is part of the admin section. there are a few php based ssh terminals out there. perhaps embed a terminal where you can see the output of the script but not interact. at the end it would give you the filename and location and close the session that way there isnt any risk of exploit of the terminal and we can go in and get that file as needed. just a thought
Need a good VPS Host? Check Out Digital Ocean! https://www.digitalocean.com/?refcode=5cc7d2894482
Reply
Thanks given by:
#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:
#15
RE: Fixing backup module
Been thinking too about adding 2 fileds in the DB so you keep more history for db's than files ( use less space ) and per account setting history to keep too ( enable/ disable), but need to be added in the GUI too.

Thanks for the update.

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask
Coldfusion Freelance

10$ free to start your VPS

Reply
Thanks given by:


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

Forum Jump:


Users browsing this thread: 1 Guest(s)