![]() |
|
Fixing backup module - Printable Version +- Sentora Support Forums (https://senforums.mach-hosting.com) +-- Forum: General Forums - (Non-Sentora Support) (https://senforums.mach-hosting.com/forumdisplay.php?fid=1) +--- Forum: Sentora Development (https://senforums.mach-hosting.com/forumdisplay.php?fid=54) +--- Thread: Fixing backup module (/showthread.php?tid=242) Pages:
1
2
|
RE: Fixing backup module - jacobg830 - 09-17-2014 Great to see you are sorting out the backup module 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 but works on Ubuntu
RE: Fixing backup module - Me.B - 09-17-2014 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 RE: Fixing backup module - webnetvn - 09-18-2014 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 RE: Fixing backup module - maleabil - 04-06-2016 (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"RE: Fixing backup module - Me.B - 04-06-2016 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 RE: Fixing backup module - betatester3.0 - 09-13-2017 Anyone get the backup module working as my module after a backup, when I hit download it sends me to a 403 forbidden page, I am assuming because its in the '/tmp' directory or inefficient permission to access or download the file without the need of downloading it via FTP or any other filemanager ? RE: Fixing backup module - Me.B - 09-13-2017 manual backup is disabled RE: Fixing backup module - betatester3.0 - 09-13-2017 (09-13-2017, 12:40 AM)Me.B Wrote: manual backup is disabled
RE: Fixing backup module - TGates - 09-13-2017 Yes, for security reason, the backups are not downloadable (They used to be until a vulnerability was found). You need to use ftp or SSH to get them. There was a module that would sent your backups to the cloud for storage but I am not sure if that one even works anymore. |