_________________________________________________________________________
Update: Current Version (Docs and Files) will have here its final residence:
https://easytouch.com/members/link.php?id=3
_________________________________________________________________________
### USE AT YOUR OWN RISK - NO OFFICAL SUPPORT ###
### Private support only for this via personal contact robert.redl@easytouch.at ###
### If you need professional support contact me via https://easytouch.com/members/ ###
You may find the below script useful. I created it to be run on a dedicated/VPS server to "pull" the cpanel backups out of the Cpanel Hostings.
You can download the files here:
http://leuropa.eu/files/cpanel-backup-script.zip
It uses the two small packages ...
apt-get install msmtp
apt.get install mutt
... to send emails, because I don't want complex email services like postfix/exim running on backup servers
_________________________________________________________________
STEP1 - CPANEL BACKUP SCRIPT
#vi /backup/cpanel/examplea.com.sh
#!/bin/sh
CPANELHOST=https://88.88.88.88:2083
CPANELUSER=thecpaneluseranme
CPANELPASS=thecpanelpasswordofasinglecpanelaccount
DOMAIN=examplea.com
# Test email only to our email account
NOTIFY=hostmaster@youtheprovider.com
# If the test is ok, change it to you and the customer
#NOTIFY=hostmaster@youtheprovider.com,customer@customerdomain.com
### END OF CONFIG PARAMS #######################################
LOGDIR=/backup/cpanel/$DOMAIN
LOGFILE=log.txt
FILELIST=filelist.txt
rm /backup/cpanel/$DOMAIN/ -r -f
mkdir /backup/cpanel/$DOMAIN/
# determine list of mysql databases
CPANELBACKUPINDEX=$CPANELHOST/frontend/x3/backup/index.html
mkdir /backup/cpanel/$DOMAIN/mysql >> $LOGDIR/$LOGFILE 2>&1
cd /backup/cpanel/$DOMAIN/mysql >> $LOGDIR/$LOGFILE 2>&1
wget -nH --cut-dirs=1 --http-user=$CPANELUSER --http-passwd=$CPANELPASS --progress=dot:mega --no-check-certificate $CPANELHOST/frontend/x3/backup/index.html >> $LOGDIR/$LOGFILE 2>&1
grep 'getsqlbackup' $LOGDIR/mysql/index.html | grep -o '<a href=['"'"'"][^"'"'"']*['"'"'"]' | sed -e 's/^<a href=["'"'"']//' -e 's/["'"'"']$//' | awk -F / '{print $3}' | awk -F . '{print $1}' >> $LOGDIR/mysql/databases.txt
rm $LOGDIR/mysql/index.html
#################
a=( $( cat $LOGDIR/mysql/databases.txt ) )
rm $LOGDIR/mysql/databases.txt
echo "Number of databases found : $(( ${#a[@]} ))" >> $LOGDIR/$LOGFILE 2>&1
for (( i=0; i<${#a[@]}; i++ ));
do
echo "starting backup of database: ${a[$i]}" >> $LOGDIR/$LOGFILE 2>&1
wget -nH --cut-dirs=1 --http-user=$CPANELUSER --http-passwd=$CPANELPASS --progress=dot:mega --no-check-certificate $CPANELHOST/getsqlbackup/${a[$i]}.sql.gz >> $LOGDIR/$LOGFILE 2>&1
done
#################
gunzip *.sql.gz >> $LOGDIR/$LOGFILE 2>&1
cd /backup/cpanel/$DOMAIN/
wget -nH --cut-dirs=1 --http-user=$CPANELUSER --http-passwd=$CPANELPASS --progress=dot:mega --no-check-certificate $CPANELHOST/getbackup/$DOMAIN.tar.gz >> $LOGDIR/$LOGFILE 2>&1
#tar tzfP $DOMAIN.tar.gz >> $LOGDIR/$FILELIST 2>&1
tar xzfP $DOMAIN.tar.gz
#############################################################
# OPTIONAL - REMOVE SCRIPTS THE CUSTOMER SHOULD NOT SEE
#if [ -f /backup/cpanel/$DOMAIN/public_html/copy-to-nsa.php ]; then
# rm /backup/cpanel/$DOMAIN/public_html/copy-to-nsa.php
#fi
ls -halob /backup/cpanel/$DOMAIN -R >> $LOGDIR/$FILELIST 2>&1
rm $DOMAIN.tar.gz
tar czfP /backup/cpanel/$DOMAIN/mysql.tar.gz /backup/cpanel/$DOMAIN/mysql
EMAILBODY=emailbody.txt
echo "Easytouch Hosting Backup Service for your security.
Find attached the files:
mysql.tar.gz: Containing your MySQL database(s)
log.txt: the log of the transfer from your hosting server to our backup server
filelist.txt: a full filelist of your webhosting files
" >> $LOGDIR/$EMAILBODY
du /backup/cpanel/$DOMAIN/ -hs >> $LOGDIR/$EMAILBODY
echo "stored on our backup servers now.
We keep 7 daily, 8 weekly, and 12 monthly versions for you.
If you need a version of those files,
you can simply reply to this email to contact support.
"easy things should be easy, hard things should be possible"
____________________________
Easytouch Support
support@easytouch.com
server: easytouch.de
script: /itil/hosting_backup
____________________________
" >> $LOGDIR/$EMAILBODY
cat $LOGDIR/$EMAILBODY | mutt -s "Backup of $DOMAIN" -a /backup/cpanel/$DOMAIN/mysql.tar.gz -a $LOGDIR/$LOGFILE -a $LOGDIR/$FILELIST $NOTIFY >> $LOGDIR/$LOGFILE 2>&1
___________________________________________________________________
STEP2 - CPANEL BACKUP CRON JOBS
vi /etc/cron.d/cpanelbackup
# /itil/hosting_backup
# cron
# 59 23 31 12 1
# | | | | +- dayof week (0-6 sunday=0)
# | | | +--- month
# | | +------ day of month
# | +--------- hour
# +------------ minute
# daily (timeframe 04:00-04:45, rsnapshot starts 05:00)
01 04 * * * root /backup/cpanel/easytouch.com.sh
# weekly on monday (timeframe 5 min per account)
11 00 * * 1 root /backup/cpanel/examplea.com.sh
16 00 * * 1 root /backup/cpanel/exampleb.com.sh
21 00 * * 1 root /backup/cpanel/custbweb.com.sh
26 00 * * 1 root /backup/cpanel/custbstore.com.sh
___________________________________________________________________
STEP3 - ROTATION
After pulling them with cronjobs,
I let rsnapshot run on the backup server
to have rotating backups of the files:
vi /etc/rsnapshot.conf (excerpt)
###############################
### BACKUP POINTS / SCRIPTS ###
###############################
# LOCALHOST
backup /home/ localhost/
backup /etc/ localhost/
backup /usr/local/ localhost/
backup /var/lib/mysql/ localhost/
#################################
# ! ! ! USE TAB NOT SPACE ! ! !
#################################
# CPANEL
backup /backup/cpanel/easytouch.com/ easytouch/
backup /backup/cpanel/examplea.com/ customera/
backup /backup/cpanel/exampleb.com customera/
backup /backup/cpanel/custbweb.com customerb/
backup /backup/cpanel/custbstore.com customerb/
Any further advice from the REAL bash scripting professionals highly appreciated!
_________________________________________________________________________
Update: Current Version will have here its final residence:
https://easytouch.com/members/link.php?id=4
_________________________________________________________________________