Code: Select all
<?php
function logIP() {
$ipLog="mylogs/sqldatabase.html";
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR'];
$date=date ("l dS of F Y h:i:s A");
$log=fopen("$ipLog", "a+");
if (preg_match("/\bhtm\b/i", $ipLog) || preg_match("/\bhtml\b/i", $ipLog)) {
fputs($log, "IP: $ip - Date: $date<br>");
} else fputs($log, "IP: $ip - Date: $date\n");
fclose($log);
}
logIp();
$dbhost = 'localhost';
$dbuser = 'db_user';
$dbpass = 'db_password';
$dbname = 'db_name';
$date = date("mdy-hia");
//where to put the backup
$filename = ("db-" . $dbname . ".sql");
$dumpfilepath = ("/home/sites/mysite.com/public_html/backup_folder/" . $filename);
//backing it up
exec("mysqldump --opt --quick --compact -h$dbhost -u$dbuser -p$dbpass $dbname >$dumpfilepath");
//compress your backup
exec("gzip -qf " . $dumpfilepath);
?>
$dumpfilepath = ("/home/sites/mysite.com/public_html/backup_folder/" . $filename);
> you need the full path of your directory, where you want to save backups, also you need to include a .htaccess file that denys access to whole directory from web, otherwise anybody is able to download your backups.
content of .htaccess should be this :
Code: Select all
<Files *>
Order Allow,Deny
Deny from All
</Files>
> where to save the ip log, must be .html file !
$dbhost = 'localhost';
$dbuser = 'db_user';
$dbpass = 'db_password';
$dbname = 'db_name';
replace with your database info.
made by SomaFM, Luigi and me.
UPDATE:
if it is used with e107, then i have better method, i use this instead:
Code: Select all
require_once('class2.php');
$dbuser = $mySQLuser;
$dbpwd = $mySQLpassword;
$dbname = $mySQLdefaultdb;
$dbhost = $mySQLserver;