Home · Mods · Super DB Backup

mods »

Super DB Backup
07.07.2009. 01:38 | Comments (2)

Note:
First I want to Thank you to Frederic Cloquell (Bramsyur) - sNews1.6 mod.

With this mod you can do:
- Backup your database and will be sent a copy to your e-mail
- Restore your database when it was damage
- Apply a cron job to save database everytime you want

Instructions:


1-Back up your files and snews.php


2-Add this lines to your lang file (EN.php)

 #BACKUP
 
$l['t_dir_backup'] = 'Folder to backup files';
 
$l['t_dbbackup'] = 'Database Backup';
 
$l['t_dbbackup_info'] = 'Please, verify or moddify the e-mail that your want to be used to get the database backup file.<br />';
 
$l['t_dbbackup_name'] = 'Database name';
 
$l['t_dbbackup_email'] = 'E-mail to send your created backup';
 
$l['t_backup'] = 'Backup now';
 
$l['t_system_mail'] = 'System DB-Backup';
 
$l['t_dbb_subject'] = 'MySQL Backup';
 
$l['t_dbb_message'] = 'MySQL Backup created successfully.';
 
$l['db_backup_directory'] = 'Currently Backup Files';
 
$l['db_no_files_found'] = 'No files found!';
 
$l['dbbackup'] = 'Admin MySQL Backup';
 

3-Edit configuration on "dbbackup.php"

First edit with correct information to work perfectly
 
#DATABASE CONFIGURATION
function db2($variable) {
    
$db = array(
        
'dbhost'     => 'localhost'// MySQL host
        
'dbname'     => 'database',
        
'dbuname'     => 'username'// Database Username
        
'dbpass'     => 'password'// Database password
        
'prefix'     => '' // Table prefix
    
); return $db[$variable];

Next edit constants
 // CONSTANTS
define('SECURE_ID','12345');
define('USERNAME''admin');
define('PASSWORD',md5('test').date('d-m-YH'));
define('_PRE',db2('prefix'));
define('pw','password'); // plain password to auto backup
 

After this save file and copy to your root domain or where you have snews.php


4-Create backups folder

Change permitions to chmod 777
If you use coreftp make a right click on backups folder and choose properties, like this pictures

coreftp coreftp

5-Update your database with phpMyAdmin

On your CPanel or other, choose phpMyAdmin:
cpanel
Next copy this code to sql box and submit
 INSERT INTO `settings` (namevalueVALUES ('dir_db'''); 

cpanel

6-Open your snews.php

a) In line cat_listSEF add red text at end
if (_ADMIN) {$l['cat_listSEF'] .= ',administration...,admin_groupings,dbbackup';}

b) After this line add this line
 include_once('dbbackup.php'); 

c) Find first line and add 2nd line on center function
 case 'snews_settings'settings(); return; break;
 case 
'dbbackup'dbbackup(); return; break; 

d) In Administration function find first line and add 2nd line
 echo '<p><a href="snews_settings/">'.l('settings').'</a></p>
    <p><a href="dbbackup/" title="'
.l('t_dbbackup').'">'.l('t_dbbackup').'</a></p>
    <p><a href="snews_files/">'
.l('files').'</a></p></fieldset></div> 

e) In processing function
Add first line before "case 'hide'
 case 'dbbackup_start'case_dbbackup();    break;
 case 
'hide':
 case 
'show'

f) Save snews.php


7-For who wants to add cron job


a) First you need to know the correct command to add cron job
To help you I add function that tells everything you need.

Upload your files to the server and put this on your browser
http://www.your_domain.com/dbbackup.php?task=cron

b) After know cron command
You need to open dbbackup.php and erase this line
 # AFTER TO GET THIS INFORMATION COMMENT OUT OR ERASE NEXT LINES
// START CRON INFO
if ($_GET['task']=='cron'){
    
$path $_ENV['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME'];
    
$path str_replace('dbbackup.php','',$path);
    
$cron 'cd ''.$path.'' ; php -q 'dbbackup.php' '?' 'task=auto' 'pw='.pw.'' ; > /dev/null ;';
    echo 
$cron;

// END CRON INFO 

Save and upload dbbackup.php again

c) Goto CPanel and open Cron Jobs
Add cron command on 3rd picture
cpanel cpanel cpanel
In last picture you can define what hour you want backup database

8-You can make a database manually, ignoring last step


cpanel cpanel

9-Recover a damage database


To recover you need to know your_password (constant pw), on dbbackup.php
http://www.your_domain.com/dbbackup.php?task=recover&pw=your_password
cpanel

10-Download


You can download dbbackup.zip here

Comments

Poppoll 09.07.2009. 01:31

Rui,
Thanks, I'll add this to my next sNews template.
Poppoll

PS Have a look @ http://mdj.us/snews-cms/themes-templates/admin-styles-for-snews-17/
for a better snews style! (the website url is to short!!)

fast loans 02.07.2010. 16:01

I stumbled onto your blog and read a few post. I like your style of writing.

Write a comment

* = required field

:

:

:


7 + 7 =