sNews Forum

sNews 1.6 (previous version) => Mods/addons => Topic started by: bramsyuur on May 19, 2007, 12:58:54 am

Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on May 19, 2007, 12:58:54 am
Information:
MOD name: Simple MySQL Backup v.01 (no system calls)
sNews version: v1.6

Function: With this mod you can create a compressed file backup of your current database from your administration panel by one click. The system ask to you a valid email address to send to you a copy of a compressed dabatase file. The backup of the database include database structure and data, all ready to be uploaded into your website if you get a disaster.

Updates:
- Fixed step 2. Thanks to Philmoz!
- Added info to chmod 777 database folder.
- Fixed, in the step 6, an error related to e-mail to user.

Quote
This is my second version of this mod (without system calls, my previous one are in the sNews 1.5.31 mod section (http://www.solucija.com/forum/viewtopic.php?id=3623)).
Important note:
Quote
If your hosting provider don't support gZip compression your database backup will be saved in a plain text.
So... let's go! :)
Step #1:
Create a backup of your snews.php file... as you know! ;)
Next, make a folder into the root of your sNews installation to store your database backups and chmod it to 777, in this mod, I've named it as _backups_ but I recommend to you to use a better name folder with alphanumerical / upper and lower case characters like: M1b4ckUp2007 for example and put inside of this folder an empty index.html file to list protection. (hey! this is not a great protection in any case, but is a minimal option for protect your folder).

Create a set of language variables used in this mod:
Quote
//MOD START: DBBackup by bramsyuur
   $l['t_dbbackup'] = 'Database Backup';
   $l['t_dbbackup_info'] = 'Please, first, provide a \' <b>backup name</b>\' for the database and, next, verify or moddify the e-mail that your want to be used to get the database backup file.
';
   $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 <admin@your.domain.com>';  // <--- Please, check this e-mail address to meet your needs!!
   $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!';
   //MOD END
Step #2:
Into "#SYSTEM VARIABLES (not to be translated)" locate:
Code: [Select]
$l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,articles,extra_contents,pages,settings,files,logout'; //SEF links of the hardcoded categoriesand replace with:
Code: [Select]
$l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,articles,extra_contents,pages,settings,files,logout,dbbackup'; //SEF links of the hardcoded categoriesStep #3:
Inside the "function center()" locate "case 'settings': settings(); return; break;" and just next to it, put:
Quote
//MOD START: DBBackup by bramsyuur
case 'dbbackup': dbbackup(); return; break;
//MOD END
Step #4:
Find, inside "function administration()" this line:
Quote
echo '<p><a href="settings/" title="'.l('settings').'">'.l('settings').'</a></p>';
And add next to it, this:
Quote
//MOD START: DBBackup by bramsyuur
echo '<p><a href="dbbackup/" title="'.l('t_dbbackup').'">'.l('t_dbbackup').'</a></p>';
//MOD END
Step #5:
Next, few lines down, under the same function (function administration()) locate "}}" and, next to it, add:
Remember: Change _backups_ with your created backup folder!!!!
Code: [Select]
//MOD START: DBBackup by bramsyuur
function dbbackup() {
echo html_input('form', '', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&task=dbbackup_start', '');
echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '','<a title="'.l('t_dbbackup').'">'.l('t_dbbackup').'</a>');
echo l('t_dbbackup_info');
echo html_input('text', 't_dbbackup_name', 't_dbbackup_name', db('dbname'), l('t_dbbackup_name'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 't_dbbackup_email', 'tdbm', s('website_email'), l('t_dbbackup_email'), '', '', '', '', '', '', '', '', '', '');
echo '
';
echo html_input('submit', 'do_backup', 'do_backup', l('t_backup'), '', 'button', '', '', '', '', '', '', '', '', '');
echo '

<p>'.l('db_backup_directory').':</p>';
     dbbackup_files("_backups_");  // REMEMBER: Change _backups_ with your created backup folder!!!!
echo '</fieldset></form>';
}

function email_att ($from , $to, $subject, $message, $attachment){
$fileatt = $attachment;
$fileatt_type = "application/octet-stream";
     $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
$fileatt_name = substr($attachment, $start, strlen($attachment));
$email_from = $from;
$email_subject =  $subject;
$email_txt = $message;
$email_to = $to;
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="\n\n";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
            "Content-Type: multipart/mixed;\n" .
            " boundary=\"{$mime_boundary}\"";
$email_txt .= $msg_txt;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
                "--{$mime_boundary}\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
               "Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$fileatt_type};\n" .
                  " name=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
                 $data . "\n\n" .
                  "--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
}

function PrintOut($output,$tbl,$stats) {
   $output = "--\n-- Table structure for `$tbl`\n--\n\nCREATE TABLE `$tbl` ( ";
   $res = mysql_query("SHOW CREATE TABLE $tbl");
   while($al = mysql_fetch_assoc($res)) {
  $str = str_replace("CREATE TABLE `$tbl` (", "", $al['Create Table']);
  $str = str_replace(",", ",", $str);
  $str2 = str_replace("`) ) TYPE=MyISAM ", "`)\n ) TYPE=MyISAM ", $str);
  if ($stats) $str2 = $str2." AUTO_INCREMENT=".$stats;
  $output .= $str2.";\n\n";
}
$output .= "-- \n-- Dumping data for table `".$tbl."`\n-- \n\n";
   $data = mysql_query("SELECT * FROM $tbl");
   while($dt = mysql_fetch_row($data)) {
  $output .= "INSERT INTO `$tbl` VALUES('$dt[0]'";
  for($i=1; $i<sizeof($dt); $i++) {
  $dt[$i] = mysql_real_escape_string($dt[$i]);
  $output .= ", '$dt[$i]'";
  }
  $output .= ");\n";
   }
   $output .= "\n-- --------------------------------------------------------\n\n";
   return $output;
}

function dbbackup_files($path) {
    $ignore = array('index.html', 'index.htm', 'index.php', 'cgi-bin', '.htaccess', '.', '..', 'Thumbs.db');
    $extension = array('.sql', '.sql.gz');
    $dh = @opendir($path);
    if (count(glob("$path".'/*.gz')) === 0) { echo '<p><b>'.l('db_no_files_found').'</b></p>'; }
    while (false !== ($file = readdir($dh))) {
        if(!in_array($file, $ignore) && !in_array(substr($file, -4), $extension)) {
                echo '∑ <a href="'.db('website').$path.'/'.$file.'">'.$file.'</a><br/>';
            }
        }
    closedir($dh);
}
//MOD END: DBBackup by bramsyuur
Step #6:
Finally, locate under "function processing()" the last "break;" at the end and next to it, add:
Remember: Change _backups_ with your created backup folder!!!!
Code: [Select]
//MOD START: DBBackup by bramsyuur
case 'dbbackup_start':
if (isset($_POST['do_backup'])) {
$mdb = db('dbname');
$mhost = db('dbhost');
$muser = db('dbuname');
$mpass = db('dbpass');
$dbackup_name = $_POST['t_dbbackup_name'];
$tables = array();
$pathname = "_backups_"; // REMEMBER: Change _backups_ with your created backup folder!!!!
$timestamp = '.'.date('d-m-Y');
$absolute_path = dirname(__FILE__).DIRECTORY_SEPARATOR.$pathname.DIRECTORY_SEPARATOR;
$filename = $dbackup_name.$timestamp.".sql.gz";
$temp = $dbackup_name.".sql.gz";
$gz = (bool) function_exists('gzopen');
if(!is_dir($pathname) || substr(sprintf('%o', fileperms($pathname)), -4) !="0777") {
echo "Directory '".$pathname."' either doesn't exist or you need to chmod it to 777";
exit;
}
$fileheader = "# mySQL backup ".$today."\n# Server: ".$_SERVER['SERVER_NAME']."\n#  Database: ".$mdb."\n\n";
ob_start();
flush();
unset($backup);
$backup = "";
$tab_status = mysql_query("SHOW TABLE STATUS");
if (!$tab_status) {
   echo "Error: Could not show table status! \n";
   echo 'MySQL Error: ' . mysql_error();
   exit;
}
while($all = mysql_fetch_assoc($tab_status)) {
   $tbl_stat[$all['Name']] = $all['Auto_increment'];
}
if(count($tables) == 0) {
$tables = mysql_query("SHOW TABLES FROM $mdb");
if (!$tables) {
  echo "Error: Could not list tables! \n";
  echo "MySQL Error: " . mysql_error();
  exit;
}
while($tabs = mysql_fetch_row($tables)) {
$backup .= PrintOut($backup,$tabs[0],$tbl_stat[$tabs[0]]);
}
} else {
foreach($tables as $table) {
$show_query ="SHOW TABLE STATUS FROM $mdb LIKE '$table'";
$show = mysql_query($show_query);
if (!$show) {
  echo "Error: Could not show ".$table." \n";
  echo "MySQL Error: ". mysql_error()."\n";
  exit;
}
while($tabs = mysql_fetch_row($show)) {
$backup .= PrintOut($backup,$tabs[0],$tbl_stat[$tabs[0]]);
}
}
}
if (($gz && ($zp = gzopen($absolute_path.$temp, 'wb'))) || (!$gz && ($fp = fopen($absolute_path.$temp, 'wb')))) {
if ($gz) gzwrite($zp, $fileheader, strlen($fileheader));
else fwrite($fp, $fileheader, strlen($fileheader));
}
if ($gz) {
gzwrite($zp, $backup);
gzwrite($zp, "\n\n--\n-- Backup complete! --\n--\n");
gzclose($zp);
} else {
fwrite($fp, $backup);
fwrite($fp, "\n\n--\n-- Backup complete! --\n--\n");
fclose($fp);
}
$final = $absolute_path.$filename;
@unlink($final);
rename($absolute_path.$temp, $final);
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') touch($final);
$dbb_to = $_POST['t_dbbackup_email'];
$dbb_from = l('t_system_mail');
$dbb_subject = l('t_dbb_subject');
$dbb_message = l('t_dbb_message');
$dbb_attachment = $absolute_path . $filename;
email_att ($dbb_from , $dbb_to, $dbb_subject, $dbb_message, $dbb_attachment);
ob_end_flush();
echo notification(0,'','administration');
}
break;
//MOD END
And this is all! :)
If you want, you can test it here: (user and password: test
http://snews.vietbee.net/demos/sNews16/ (http://snews.vietbee.net/demos/sNews16/)
And here's an example image:
(http://img224.imageshack.us/img224/1073/dbbackupvf2.jpg)
Thanks for using it! :)
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: piXelatedEmpire on May 19, 2007, 03:18:22 am
Without System Calls? Excellent update Bram!! :cool:
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Rui Mendes on May 19, 2007, 03:58:29 am
Excellent Work Bram! :D

 Very usefull MOD, thank you
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: philmoz on May 19, 2007, 06:10:00 am
Step 2 should read


Quote
snipped .. mod adjusted..
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on May 19, 2007, 11:46:23 am
Thanks Philmoz, I've fixed it and noted in my post.  :)
Also I've added a notice to chmod the backup folder to 777.
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on May 20, 2007, 07:21:20 pm
Fixed an error in the step 6 related to user e-mail and added an online demo to check it out!  ;)
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Rui Mendes on May 20, 2007, 10:01:58 pm
For who want default Database name with dbname_daymonthyear_hourmin

in dbbackup function, find
Code: [Select]
echo html_input('text', 't_dbbackup_name', 't_dbbackup_name', db('dbname'), l('t_dbbackup_name'), '', '', '', '', '', '', '', '', '', '');Add red text
Quote
echo html_input('text', 't_dbbackup_name', 't_dbbackup_name', db('dbname').'_'.).date('dmY'.date('H').date('i'), strtotime($r['date']))).date('dmY'.date('H').date('i'), strtotime($r['date'])) , l('t_dbbackup_name'), '', '', '', '', '', '', '', '', '', '');
or replace line complete
echo html_input('text', 't_dbbackup_name', 't_dbbackup_name', db('dbname').date('dmY'.date('H').date('i'), strtotime($r['date'])), l('t_dbbackup_name'), '', '', '', '', '', '', '', '', '', '');
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on May 21, 2007, 03:57:06 pm
Quote from: ruimendes
For who want default Database name with dbname_daymonthyear_hourmin
Rui, this mod currently add automatically a date to your data backup name. If you enter a database name like "snews16" you get as a result: snews16.20-05-2007.sql.gz.
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: piXelatedEmpire on June 11, 2007, 11:58:09 am
Quote from: bramsyuur
... I recommend to you to use a better name folder with alphanumerical / upper and lower case characters like: M1b4ckUp2007 for example and put inside of this folder an empty index.html file to list protection. (hey! this is not a great protection in any case, but is a minimal option for protect your folder).
I've been thinking about this somewhat, and an idea came to me after reading this thread (http://www.solucija.com/forum/viewtopic.php?id=4928), and seeing this in particular:
Code: [Select]
# Prevent viewing of .htaccess

order allow,deny
deny from all
satisfy all


# Prevent viewing of the data files

deny from all
Now, my thoughts are would it be possible to modify this .htaccess file and place it in the _backups_ folder for added security?  Perhaps instead of preventing data files from being viewed we could prevent .gz files from being viewed/downloaded?  Or would this impact of the MODs ability to function correctly?
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on June 11, 2007, 12:07:51 pm
I'll try to update the security of the current database folder with something like this. Wen finish I'll update my post.
Thanks pix' ! :)
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on June 11, 2007, 12:31:12 pm
Well pix, If I use any .htaaccess protection to see the .sql.gz files, one part of this mod (the current view of data backups) don't work correctly and you get an error due to protection of the .htaccess file.
If you want to use a .htaccess protection may be you need to remove the "current backups view" part of this mod.
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: piXelatedEmpire on June 11, 2007, 12:38:03 pm
That's probably not a bad idea bramsyuur.  Actually taking it a step further, do we actually need to store the database backups on the server?  I mean ideally I think it would be best if once the file was sent to the desired email address, the actual backup file was deleted.  Is that a possibility?
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on June 11, 2007, 12:39:47 pm
You're right Pix'... I'll post a 'second' version of this mod soon.
Thanks.  :)
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: piXelatedEmpire on June 23, 2007, 05:25:18 am
Hey bram, just wondering if you'd worked on this any further?  I know you've been a busy bee with the MU MOD! :D
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: bramsyuur on June 23, 2007, 12:55:12 pm
Not yet Pix' but soon... :)
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Ghassem Tofighi on August 15, 2007, 06:58:50 pm
dear bramsyuur
can you add a php cron job to your mod , and add an option to settings menu for backup and MAIL that backup to us at some time intervals ?
Title: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Ken Dahlin on August 16, 2007, 06:42:35 pm
This is exactly what I needed. Thanks!
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: solo on August 23, 2007, 03:41:36 pm
External DB Util for backup ANY MySQL database is still here : http://rapidshare.com/files/21030502/dumper.zip
Unpack it to the root of your site. That's all.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on October 28, 2007, 07:58:39 pm
Has anyone installed this mod and have it working OK online?
[EDITED] I did experience problems at first. The problem was solved quickly - moved a part of the script from one location to another - bingo - working fine now.  :)
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: funlw65 on November 02, 2007, 06:19:13 pm
Only offline, I still gather mods :) . @bramsyuur, I want to see a list with all tables from database, I want to check what I want to save because on my database I have also wordpress tables. On many ISP's here in Romania you have only one mysql database. So, this is very useful also for other cms's installed....

Is good to have a backup directory on server because your ISP can have problems with email server. And if transmission is a failure ... no backup.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on November 02, 2007, 06:41:37 pm
I don't know if anyone else has noticed... if you don't receive the back-up attached to an e-mail, you should be able to click on the file-link in the back-up panel (after doing the back-up) and download it directly to your home or office computer. It's working that way for me, both offline and online.  :)

The script will only back-up the sNews site's database right now because it is configured to use the database access information generated in the sNews database configuration variables that you enter in at the top of your snews.php (or other config) file. In order to have it work with another database, it would need to be reconfigured to do the same with other other database(s) as well. I'm not sure that its possible at this point.

Note: I don't think Bramsyuur is visiting the forums much these days. He recently got married and is working hard in his day-job... so we could say his time is 'fully consumed'. He hasn't responded to e-mails or PMs lately.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Rui Mendes on November 02, 2007, 07:48:11 pm
Yes works 100% online and offline.

So far no problems
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: funlw65 on November 02, 2007, 07:54:10 pm
The script will only back-up the sNews site's database right now because it is configured to use the database access information generated in the sNews database configuration variables that you enter in at the top of your snews.php (or other config) file. In order to have it work with another database, it would need to be reconfigured to do the same with other other database(s) as well. I'm not sure that its possible at this point............

I'm sorry Keyrock, my english is not good. In Romania, when you have a free web hosting account (www.yeahost.com), you get 50mb disk space and only one database . So, if you want to test more cms's (wordpress, e107, snews) you can do it in separate directories but all tables in that one database. So, wordpress have a prefix for his tables (something like wp_*), e107 have (by example) e107_* for his tables, etc. - a huge database. That's why I need a selection of tables from that database. sNews database is shared between snews and wordpress in my situation.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Armen on November 03, 2007, 02:09:47 pm
Outstanding mod.

Saved me a lot of time, because PhpMyAdmin doesn't like to export text in non-UTF8 codepages.
It takes hellalotofmodding to make it work.

And this mod... Simply perfect. Thank you so much.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: funlw65 on November 03, 2007, 11:57:05 pm
I think will be great to have a list or variable array with all table names of sNews. In this way, this mod can save only sNews tables from a shared mysql database. A variable in snews.php . What you think guys?
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Armen on November 04, 2007, 10:10:34 am
Good idea.

And we could add a checkbox with an option whether to backup the whole DB or just current snews' installation (based on specified prefix, I guess) part of DB.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: funlw65 on November 05, 2007, 07:09:41 pm
One more tought:

Is good to have a little mysql admin in snews. In this way, table names can be in a table. And very easy to add a new field or a table, (with table name recorded in that table). Very handy for a snews developer and easy for backup!!!
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Armen on November 05, 2007, 10:21:24 pm
One more tought:

Is good to have a little mysql admin in snews. In this way, table names can be in a table. And very easy to add a new field or a table, (with table name recorded in that table). Very handy for a snews developer and easy for backup!!!

This... I think this is a little too much. There's PhpMyAdmin for such tasks, or plenty of many other small but powerful scripts, all you have to do is to link them to sNews through your admin panel, like I did.

For example: http://phpminiadmin.sourceforge.net/

If you want, I'll teach you how to password-protect it.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: funlw65 on November 05, 2007, 11:12:16 pm
So, this tool exist! Thank you for link. Yes, I want to know how to protect it. Maybe in final version is not necessary this tool but for a snews (where nothing is settled) developer is great (I know phpMyAdmin).

So we remain at an extended version of bramsyuur mod and your ideea: saving entire database or just snews tables.

Yes! This minitool is great with export/import functions. Thank you again!
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Armen on November 06, 2007, 12:23:16 am
Here's the addon:

http://snewscms.com/forum/index.php?topic=6259.0
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: jackp on March 26, 2008, 04:55:27 am
Thanks bramsyuur

Needed this one about ten minutes ago. BUGGER!!     NEWBIES - BACKUP YOUR DB!!!

using sNewsMU 1.6.3 there were a few (Cosmetic) differences in mod placement,  most notable was

Step 5

Place the Step 5 Mod after the last }} just above // SETTINGS FORM
function settings() then it will work. Placed anywhere else and the Backup Panel doesn't show.

Jackp
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on July 03, 2008, 07:43:53 pm
I trying this mod, it seems to work perfectly.

About security access of the database backup folder, I'm wondering if a simple index.html file with a http redirect to the home page
and absolutely no content at all on it would be a good protection ?
If somebody find the database folder and try to access in it it will go on the home page !

What do you think ?
Stephane
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on July 03, 2008, 08:00:00 pm
You might try that. Any index.htm file in a folder will be automatically delivered by the server if the folder name itself is added to the root URL. If empty, a blank page will display. I've not tried a redirect script there but I assume it would work.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on July 04, 2008, 11:44:42 am
With a simple empty index.htm file in this folder I have a blank page, normal.

With a htm redirect (with no text at all) I go on the home page. Like if the database folder doesn't exist  :P
But I'm not sure if that solution is a great security ??

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="refresh" content="0; url=http://localhost:8888/snews16/" />
</head>
<body>
<p><a href="http://localhost:8888/snews16/"></a></p>
</body>
</html>
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: codetwist on July 04, 2008, 12:10:02 pm
It's not great as it's based on obscurity. With index added it depends on backup file names not being guessable. If You enter proper url to that directory and file name then it's content will be revealed. So, either make them hard to guess or add .htaccess rules that'd restrict access from web.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on July 07, 2008, 11:50:30 pm
If I put in top on the sNews htaccess file this sentence : Options -Indexes

We can't access anymore to any folder or subfolders. And it's still possible to have the list of database files save in the admin area.
What do you think of this solution ? Looks fine ?
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Joost on July 08, 2008, 02:35:33 am
If I put in top on the sNews htaccess file this sentence : Options -Indexes

We can't access anymore to any folder or subfolders. And it's still possible to have the list of database files save in the admin area.
What do you think of this solution ? Looks fine ?

NO!, Options -Indexes means that Apache doesn't generate an index for the browser (example (http://ftp://ftp.calyx.nl/pub/OpenBSD/)). Switching that off, does not mean, it is inaccessible (just harder to find).
The database dump, includes your (encrypted) passwords, so preferably, you want the file created in a nonpublic folder, below the siteroot and make it non=worldreadable (chmod to 0644 or something else compliant to the server configuration).
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on July 08, 2008, 11:15:21 am
Ok ok.
But if the folder for database save is not in 777 we can't make the backup with this Mod !

Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on July 08, 2008, 04:01:08 pm
Ok ok.
But if the folder for database save is not in 777 we can't make the backup with this Mod !

This is true. However... what I do is give the folder a unique name that is not easy for anyone else to guess. I use this mod on several sites (mine and clients) and I always download the backups to my computer after creating them... and delete them from the folder on the domain server... so there are none there for anyone to find. This eliminates the problem altogether... for me.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on July 08, 2008, 05:18:03 pm
Yes you right, probably the best solution.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: stephane on June 16, 2009, 01:45:26 pm
Hi,
I'm try to use this MOD with Snews 17. Seem to work fine  :)
I change a little bit for 17 but I can't find where the Title name (top of browser)) goes.

ex: In admin area  > Settings We got a title name like :  Settings - Name site

In Backups admin area I got only the Name site like this :  - site name
Instead of Backups - site name

I change little thing for snews 17:
Code: [Select]
$l['cat_listSEF'] =  'archive,contact,sitemap,login,administration,admin_category,admin_article,article_new,extra_new,page_new,snews_categories,snews_articles,extra_contents,snews_pages,snews_settings,snews_files,logout,groupings,admin_groupings,dbbackup';

Next in function Center I put the DBBackup just under case 'snews_file'
Code: [Select]
case 'snews_files':
files(); return; break;
//MOD START: DBBackup by bramsyuur
case 'dbbackup': dbbackup(); return; break;
//MOD END

Then in Admin area
Code: [Select]
echo '<p><a href="snews_settings/">'.l('settings').'</a></p><p><a href="snews_files/">'.l('files').'</a></p><p><a href="dbbackup/">'.l('t_dbbackup').'</a></p></fieldset></div>';

I didn't change after.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Sven on February 17, 2010, 02:23:08 pm
Au secours !!!
Hello boys
I sware I didn't touch anything to my old 1.6 sNews Core.  ;)
It has worked for months and years and now this is the message I got when trying to backup:
Quote
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in .../../myspace/snooze2MT.php on line on line 2638
What's happening?
Is that a server error, a DB error, a Sven error?
Tell me please I feel really bad. :-[
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on February 17, 2010, 03:18:00 pm
Au secours !!!
Hello boys
I sware I didn't touch anything to my old 1.6 sNews Core.  ;)
It has worked for months and years and now this is the message I got when trying to backup:
Quote
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in .../../myspace/snooze2MT.php on line on line 2638
What's happening?
Is that a server error, a DB error, a Sven error?
Tell me please I feel really bad. :-[

This is caused by a PHP Max. Size limiter set to 8 MB on your host's server.

A Search on Google for Fatal error: Allowed memory size of 8388608 bytes (http://www.google.ca/search?hl=en&q=Fatal+error%3A+Allowed+memory+size+of+8388608+bytes&btnG=Search&meta=&aq=null&oq=Fatal+error%3A+Allowed+memory+size+of) will return a whole bunch of references to this issue... about 71,000 or so.

Check out any of the solutions offered on the first Google page. It seems your d-base backup file is over 8 MB in size (pretty big for a Snooze d-base) and you'll need to over-ride the server's PHP max size limit with one of the solutions offered.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Joost on February 17, 2010, 03:55:51 pm

 It seems your d-base backup file is over 8 MB in size (pretty big for a Snooze d-base)

It is not file size that's over 8 MB. It's memory size that's over 8 MB.

Quote
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in .../../myspace/snooze2MT.php on line on line 2638
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Sven on February 17, 2010, 04:05:44 pm
Au secours !!!
Hello boys
I sware I didn't touch anything to my old 1.6 sNews Core.  ;)
It has worked for months and years and now this is the message I got when trying to backup:
Quote
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in .../../myspace/snooze2MT.php on line on line 2638
What's happening?
Is that a server error, a DB error, a Sven error?
Tell me please I feel really bad. :-[

This is caused by a PHP Max. Size limiter set to 8 MB on your host's server.

A Search on Google for Fatal error: Allowed memory size of 8388608 bytes (http://www.google.ca/search?hl=en&q=Fatal+error%3A+Allowed+memory+size+of+8388608+bytes&btnG=Search&meta=&aq=null&oq=Fatal+error%3A+Allowed+memory+size+of) will return a whole bunch of references to this issue... about 71,000 or so.

Check out any of the solutions offered on the first Google page. It seems your d-base backup file is over 8 MB in size (pretty big for a Snooze d-base) and you'll need to over-ride the server's PHP max size limit with one of the solutions offered.
Yeap it's more than 8Mb: I now use Piwik (http://piwik.org/) for my stats. And I'm now receiving a lot of visitors...
I've tried this php ini (memory_limit = 12M)  trick and tried the php line at the top of my index file: in both cases there were no more errors but no more backup. ;D

I've tried every solutions (even with an .htaccess which lead to a 500 error) in vain.
As my provider is 1and1 I guess there is a different solution to try.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Joost on February 17, 2010, 04:15:06 pm
I have little time to or explain and no time to write code, so in short:
The script you're using uses to much memory (as said) to process a file (dump) that is probably a lot smaller.
You can however, use an external program: mysqldump.
Here is an example taken from PHP MySQL Tutorial (http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx). Mysql is started by the php command system, which is unfortunately, not enabled on every server.

<?php
include 'config.php';
include 'opendb.php';

$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);
include 'closedb.php';
?>
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Sven on February 17, 2010, 05:09:39 pm
Okey okey...
I'm gonna try it.
Merci beaucoup Joostey.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Sven on February 18, 2010, 07:55:05 am
And the winner is... Joostey!
Made it "fingers in the nose". ;D
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Joost on February 18, 2010, 05:37:09 pm
Inspecteur, vous Ítes le champion. You have created a mod all by yourself. Karma.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Sven on February 19, 2010, 11:20:23 am
Inspecteur, vous Ítes le champion. You have created a mod all by yourself. Karma.
Yeap. And for myself only.
And as you've scratched my back with a karma, I've scratched yours too.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Pein on August 23, 2010, 04:05:40 pm
Howdy,

can someone more userfriendly show where must go the new code?! Cuz Im not getting it to work all errors! Please!

Greetings,
David

Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on August 23, 2010, 04:16:27 pm
Howdy, can someone more userfriendly show where must go the new code?! Cuz Im not getting it to work all errors! Please!
Greetings, David

Hi David:
Question: Are you installing it with an sNews 1.6 or sNews 1.7 package?
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Pein on August 23, 2010, 04:51:53 pm
Howdy, can someone more userfriendly show where must go the new code?! Cuz Im not getting it to work all errors! Please!
Greetings, David

Hi David:
Question: Are you installing it with an sNews 1.6 or sNews 1.7 package?

Howdy Key,

im trying it to install with 1.7. I hope this one doesnt uses exec.
Title: Re: [MOD] Simple MySQL Backup v0.1 (no system calls)
Post by: Keyrocks on August 23, 2010, 05:01:17 pm
Howdy Key, im trying it to install with 1.7. I hope this one doesnt uses exec.

Updated: Here is the sNews 1.7 Version (http://snewscms.com/forum/index.php?topic=9287.0).