Jump to content











Photo
* * * * * 1 votes

Backup your Site !


  • Please log in to reply
2 replies to this topic

#1 Mikorist

Mikorist

    ▂ ▃ █ ▅ ▆

  • Advanced user
  • 771 posts
  •  
    United Nations

Posted 16 August 2010 - 01:19 PM

Many have lost their sites because they did not have backup ! :(

Write here the various ways to Backup !

Configuring CRON:
To run it as a cron job (at 3:30am as example), put something in your crontab like the following (if the script is in your top directory):

30 3 * * * /usr/local/bin/php /home/youraccount/fullbackup.php

Backup with cPanel

fullbackup.php
<?php



// PHP script to allow periodic cPanel backups automatically.

// Based on script posted by max.hedroom in cpanel.net forums

//   This script contains passwords.  KEEP ACCESS TO THIS FILE SECURE!



// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********



// Info required for cPanel access

$cpuser = &#34;username&#34;; // Username used to login to CPanel

$cppass = &#34;password&#34;; // Password used to login to CPanel

$domain = &#34;example.com&#34;; // Domain name where CPanel is run

$skin = &#34;monsoon&#34;; // Set to cPanel skin you use &#40;script won&#39;t work if it doesn&#39;t match&#41;



// Info required for FTP host

$ftpuser = &#34;ftpusername&#34;; // Username for FTP account

$ftppass = &#34;ftppassword&#34;; // Password for FTP account

$ftphost = &#34;ftp.example.com&#34;; // Full hostname or IP address for FTP host

$ftpmode = &#34;ftp&#34;; // FTP mode &#40;&#34;ftp&#34; for active, &#34;passiveftp&#34; for passive&#41;



// Notification information

$notifyemail = &#34;you@example.com&#34;; // Email address to send results



// Secure or non-secure mode

$secure = 0; // Set to 1 for SSL &#40;requires SSL support&#41;, otherwise will use standard HTTP



// Set to 1 to have web page result appear in your cron log

$debug = 0;



// *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********



if &#40;$secure&#41; {

	$url = &#34;ssl&#58;//&#34;.$domain;

	$port = 2083;

} else {

	$url = $domain;

	$port = 2082;

}



$socket = fsockopen&#40;$url,$port&#41;;

if &#40;!$socket&#41; { echo &#34;Failed to open socket connection... Bailing out!\n&#34;; exit; }



// Encode authentication string

$authstr = $cpuser.&#34;&#58;&#34;.$cppass;

$pass = base64_encode&#40;$authstr&#41;;



$params = &#34;dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$

ftpuser&pass=$ftppass&submit=Generate Backup&#34;;



// Make POST to cPanel

fputs&#40;$socket,&#34;POST /frontend/&#34;.$skin.&#34;/backup/dofullbackup.html?&#34;.$params.&#34; HTTP/1.0\r\n&#34;&#41;;

fputs&#40;$socket,&#34;Host&#58; $domain\r\n&#34;&#41;;

fputs&#40;$socket,&#34;Authorization&#58; Basic $pass\r\n&#34;&#41;;

fputs&#40;$socket,&#34;Connection&#58; Close\r\n&#34;&#41;;

fputs&#40;$socket,&#34;\r\n&#34;&#41;;



// Grab response even if we don&#39;t do anything with it.

while &#40;!feof&#40;$socket&#41;&#41; {

   $response = fgets&#40;$socket,4096&#41;;

   if &#40;$debug&#41; echo $response;

}



fclose&#40;$socket&#41;;



?>


Based on script posted by max.hedroom in cpanel.net forums
-----------------------------------------------------------------


Easiest way is to wget the backup from the remote location

you need to have wget (for Windows) : http://gnuwin32.sour...ckages/wget.htm

If the database was called "diyaudio" for example, you would do something like this:

wget --http-user=cpaneluser --http-passwd=cpanelpassword https&#58;//example.com&#58;2083/getsqlbackup/diyaudio.gz

after that make getsqlbackup.cmd with this line and Run every 12 hours. :(

#2 Mikorist

Mikorist

    ▂ ▃ █ ▅ ▆

  • Advanced user
  • 771 posts
  •  
    United Nations

Posted 16 August 2010 - 01:43 PM

Sys32.org Full Backup Script

This script create and store last 10 days of Full Backups in separate folders DATABASES & SITES
Automatically delete all older data backups ...

backup.sh
#!/bin/bash



# Full Backup Script

# VER. 1.0 - http&#58;//sys32.org/

#

#This sript is free; you can redistribute it and/or modify it under the terms of the 

#GNU General Public License as published by the Free Software Foundation

#

# Copyleft &#40;c&#41; 2010



#System Setup

NOW=$&#40;date +&#34;%d-%m-%Y&#34;&#41;

DAY=$&#40;date +&#34;%a&#34;&#41;

DATE=$&#40;date&#41;

MUSER=&#34;MYSQL-USER-NAME&#34;

MPASS=&#34;MYSQL-PASS&#34;

MHOST=&#34;localhost&#34;

MYSQL=&#34;$&#40;which mysql&#41;&#34;

MYSQLDUMP=&#34;$&#40;which mysqldump&#41;&#34;

GZIP=&#34;$&#40;which gzip&#41;&#34;

BU_FILE_COUNT=0

BU_BASE_COUNT=0

WEBDIR=&#34;/var/www&#34;

BACKUP=&#34;/BACKUP/DATABASES&#34;

DESDIR=&#34;/BACKUP/SITES&#34;

LOG=&#34;/BACKUP&#34;

DEFRETAIN=1

TODAY=&#96;date&#96;

suffix=$NOW-$&#40;date +&#34;%T&#34;&#41;

LOGFILE=$LOG/BACKUP_$NOW.LOG



###Notification information ----> mail address to send results

MAIL1= &#34;you1@example.com&#34;

MAIL2= &#34;you2@example.com&#34;



### FTP SERVER Login info

FTPU=&#34;FTP-SERVER-USER-NAME&#34;

FTPP=&#34;FTP-SERVER-PASSWORD&#34;

FTPS=&#34;FTP-SERVER-IP-ADDRESS&#34;



BACKUP0=&#34;$BACKUP/DATABASES-$NOW&#34;

DESDIR0=&#34;$DESDIR/SITES-$NOW&#34;



find $BACKUP  -type f -mtime +10 -exec rm {} \;

find $DESDIR  -type f -mtime +10 -exec rm {} \;



mkdir -p $BACKUP0

mkdir -p $DESDIR0



cd ${WEBDIR}/



printf &#34;\n\n**************************************************************************

**************\n\tSites Backup &#58;\n\t&#34; | tee -a $LOGFILE

										echo $TODAY | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; $TODAY | tee -a $LOGFILE

echo &#34;see ${LOGFILE} for details&#34;



for folder in */

do



tar -zcf ${DESDIR0}/${folder%/}_$suffix.tar.gz ./$folder



BU_FILE_COUNT=$&#40;&#40; $BU_FILE_COUNT + 1 &#41;&#41;



done



cd ${DESDIR0}/



ls -s -altrh --format=single-column | tee -a $LOGFILE



printf &#34;\n\n**************************************************************************

**************\n&#34; | tee -a $LOGFILE

							   echo $BU_FILE_COUNT sites were backed up | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; $TODAY | tee -a $LOGFILE



### Start MySQL Backup



printf &#34;\n\n**************************************************************************

**************\n\tDatabases Backup&#58;\n\t&#34; | tee -a $LOGFILE

echo $TODAY | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; $TODAY | tee -a $LOGFILE

echo &#34;see ${LOGFILE} for details&#34;



DBS=&#34;$&#40;$MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse &#39;show databases&#39;&#41;&#34;

for db in $DBS

do

 FILE=$BACKUP0/mysql-$db.$NOW-$&#40;date +&#34;%T&#34;&#41;.gz

 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE

 BU_BASE_COUNT=$&#40;&#40; $BU_BASE_COUNT + 1 &#41;&#41;

done



cd ${BACKUP0}/



ls -s -altrh --format=single-column | tee -a $LOGFILE



printf &#34;\n\n**************************************************************************

**************\n&#34; | tee -a $LOGFILE

						  echo $BU_BASE_COUNT databases were backed up | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; $TODAY | tee -a $LOGFILE



printf &#34;\n\n**************************************************************************

**************\n\tStatistics\n\t&#34; | tee -a $LOGFILE

echo $TODAY | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; $TODAY | tee -a $LOGFILE

cd ${DESDIR}/

du -ch  | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; | tee -a $LOGFILE

cd ${BACKUP}/

du -ch  | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; | tee -a $LOGFILE

printf &#34;Backup size&#58;\n&#34; | tee -a $LOGFILE

cd ${LOG}/

du -ch | grep total | tee -a $LOGFILE

printf &#34;Total used space on disc &#58;\n&#34; | tee -a $LOGFILE

cd /root

du -ch | grep total | tee -a $LOGFILE

printf &#34;****************************************************************************

************\n&#34; | tee -a $LOGFILE

printf &#34;Site Backup Script - VER. 1.0 - http&#58;//sys32.org/  - Copyleft &#40;c&#41; 2010\n&#34;   | tee -a $LOGFILE



### Dump backup using LFTP

#lftp -u $FTPU,$FTPP -e &#34;mkdir /BACKUP/$NOW;cd /BACKUP/$NOW; mput $BACKUP0/; mput $DESDIR0/; quit&#34; $FTPS



# Email Address to send mail to&#58;

cat &#34;$LOGFILE&#34; | mail -s &#34;Site Backup Log for $NOW-$&#40;date +&#34;%T&#34;&#41;&#34; $MAIL1

cat &#34;$LOGFILE&#34; | mail -s &#34;Site Backup Log for $NOW-$&#40;date +&#34;%T&#34;&#41;&#34; $MAIL2

crontab -e


00 4 * * * /root/backup.sh


start at 04:00:00 AM every day

part of statistics:


********************************
Statistics
Mon Aug 16 04:00:01 CEST 2010
********************************
1.7G ./SITES-06-08-2010
1.7G ./SITES-15-08-2010
1.7G ./SITES-07-08-2010
1.7G ./SITES-16-08-2010
1.7G ./SITES-09-08-2010
1.7G ./SITES-12-08-2010
1.7G ./SITES-10-08-2010
1.7G ./SITES-14-08-2010
1.7G ./SITES-13-08-2010
1.7G ./SITES-11-08-2010
1.7G ./SITES-08-08-2010
19G .
19G total
*****************************
98M ./DATABASES-06-08-2010
97M ./DATABASES-12-08-2010
97M ./DATABASES-08-08-2010
97M ./DATABASES-16-08-2010
97M ./DATABASES-11-08-2010
98M ./DATABASES-14-08-2010
97M ./DATABASES-10-08-2010
98M ./DATABASES-07-08-2010
97M ./DATABASES-09-08-2010
98M ./DATABASES-13-08-2010
98M ./DATABASES-15-08-2010
1.1G .
1.1G total
*****************************
Backup size:
20G total
Total used space on disc :
114G total
******************************

License:

This sript is free; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.



This script is tested and work here on this server :(

#3 augustk

augustk
  • Members
  • 3 posts
  •  
    United States

Posted 23 March 2016 - 03:15 AM

It's cool. For those webmasters who got cPanel installed, it's easy to make backup via cPanel.


Edited by augustk, 23 March 2016 - 03:15 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users