Hi!
The idea com from here:
http://www.4homepages.de/forum/index.php?topic=18747.msg160485#msg160485Update: Step 6.) added...
This is my version,features:
- in the ACP, you can set the time in hours in which an automatic database backup should be made...
- if users with the User-ID login, start a automatic database backup...
- send database-backup as e-Mail.
- the automatic database-backup zip files are stored in a separate sub directory below database. "data/database/autobackup"
- and non zip database-backup files are stored in data/database/
- in "ACP"/"Database Backup" the automatically generated backups can be imported back into the database.
1.) copy the files from the Attachment,the folder structure according, in your galery.
2.) search in admin/settings.php:
show_form_footer($lang['save_changes'], "", 2);
insert above:
show_table_separator($setting_group["db_backup"], 2, "setting_group_db_backup");
show_setting_row("db_backup_time");
show_setting_row("db_backup_last_backup");
show_setting_row("db_backup_event");
show_setting_row("db_backup_email", "radio");
3.) search in lang/YourLang/admin.php "?>" and insert above:
(deutsch)
$setting_group["db_backup"]="Datenbank Backup";
$setting['db_backup_time'] = "Zeit in Stunden in den ein Automatisches Datenbank Backup gemacht werden soll ?";
$setting['db_backup_last_backup'] = "Letztes Automatisches Backup am:";
$setting['db_backup_event'] = "Automatisches DB-Backup soll gestartet werden wenn sich User mit der folgenden User-ID einloggen :<br><span class=\"smalltext\">Mehrere User-IDs mit einen ',' getrennt eingeben.</span>";
$setting['db_backup_email'] = "Letztes DB-Backup als eMail versenden ?";
(english)
$setting_group["db_backup"]="Database Backup";
$setting['db_backup_time'] = "Time in hours in which an automatic database backup should be made ?";
$setting['db_backup_last_backup'] = "Last automatic database backup :";
$setting['db_backup_event'] = "Automatic database backup start, if users with the following User-ID login :<br><span class=\"smalltext\">Multiple User-IDs must be separated by commas.</span>";
$setting['db_backup_email'] = "Send last automatic database backup as eMail ?";
3.1) search in lang/YourLang/main.php "?>" and insert above:
(deutsch)
$lang['db_backup_subject'] = "Automatisches Datenbank Backup";
$lang['db_backup_header'] = "Automatisches Datenbank Backup von ";
$lang['db_backup_file'] = "Dateiname:";
$lang['db_backup_done'] = "Automatisches Datenbank-Backup erfolgreich durchgeführt !";
(english)
$lang['db_backup_done'] = "Automatic database backup completed successfully !";
$lang['db_backup_file'] = "File Name:";
$lang['db_backup_subject'] = "Automatic Database-Backup";
$lang['db_backup_header'] = "Automatic Database-Backup from ";
4.) search in includes/functions.php "?>" and insert above:
function makebackup($current_time){
global $site_db, $lang, $config, $db_name, $site_mailtemplate;
$path = ROOT_PATH.DATABASE_DIR."/autobackup";
if(!is_dir($path)){
mkdir($path,0777);
chmod($path,0777);
}
include(ROOT_PATH.'includes/db_utils.php');
$db_tables = array(
CATEGORIES_TABLE,
COMMENTS_TABLE,
GROUP_ACCESS_TABLE,
GROUP_MATCH_TABLE,
GROUPS_TABLE,
IMAGES_TABLE,
IMAGES_TEMP_TABLE,
LIGHTBOXES_TABLE,
POSTCARDS_TABLE,
SESSIONS_TABLE,
SESSIONVARS_TABLE,
SETTINGS_TABLE,
USERS_TABLE
);
$tables_info = array();
$crlf = (get_user_os() == "WIN") ? "\r\n" : ((get_user_os() == "MAC") ? "\r" : "\n");
$tables_info = array();
$db = (get_mysql_version() >= 32306) ? "`$db_name`" : $db_name;
$result = $site_db->query("SHOW TABLE STATUS FROM $db");
if ($result) {
while ($row = $site_db->fetch_array($result)) {
$tables_info[$row['Name']] = ((isset($row['Type'])) ? $row['Type'] : $row['Engine']);
}
$site_db->free_result($result);
}
ob_start();
@ob_implicit_flush(0);
echo "#----------------------------------------------------------".$crlf;
echo "# Database Backup for ".$config['site_name'].$crlf;
echo "# ".date("Y-m-d H:i").$crlf;
echo "#----------------------------------------------------------".$crlf;
foreach ($db_tables as $table) {
@set_time_limit(1200);
echo $crlf."#".$crlf."# Structure for Table ".$table.$crlf."#".$crlf;
get_table_def_mysql($table, $crlf);
get_table_content_mysql($table, $crlf);
}
$contents = ob_get_contents();
ob_end_clean();
@umask(0111);
if ($config['gz_compress'] == 1 && extension_loaded("zlib")) {
$file_name = "autobackup".date("YmdHi",$current_time).".sql.gz";
$fp = gzopen(ROOT_PATH.DATABASE_DIR."/".$file_name, "w9");
$ok = gzwrite($fp, $contents);
gzclose($fp);
}
else {
$file_name = "autobackup".date("YmdHi",$current_time).".sql";
$fp = fopen(ROOT_PATH.DATABASE_DIR."/".$file_name, "w");
$ok = fwrite($fp, $contents);
fclose($fp);
}
if ((is_dir($path)) && $ok) {
/* include(ROOT_PATH."includes/zip.php");
$zipfile = new zipfile();
@set_time_limit(120);
if (!$file_data = @file_get_contents(ROOT_PATH.DATABASE_DIR."/".$file_name)) {
continue;
}
$zipfile->add_file($file_data, $file_name);
unset($file_data);
$zipfile->store($path."/".$file_name.".zip");
$zipfile_name = $file_name.".zip"; */
$backup_ok = 1;
}
if ($config['db_backup_email']){
$config['upload_emails'] = str_replace(" ", "", $config['upload_emails']);
$email_to = $config['site_email'].",".$config['upload_emails'];
$email_subject = $lang['db_backup_subject'];
$email_attachment_path = $path."/".$zipfile_name;
$email_attachment_name = $zipfile_name;
$site_mailtemplate->register_vars(array(
"lang_db_backup_file" => $lang['db_backup_file'],
"lang_date" => $lang['date'],
"file_name" => $file_name,
"subject" => $lang['db_backup_subject'],
"lang_header" => $lang['db_backup_header'],
"current_time" => format_date($config['date_format']." ".$config['time_format'], $current_time),
));
unset($file_name);
$email_template = "auto_backup_html";
include(ROOT_PATH.'includes/email_bridge.php');
$backup_ok = 1;
}
return $backup_ok;
}
function startbackup($current_time){
global $config,$site_template,$site_db;
if(!$config['db_backup_last_backup']){
$sql = "INSERT INTO ".SETTINGS_TABLE." (setting_value, setting_name)
VALUES ('$current_time', 'db_backup_last_backup')";
}
if(((strtotime($config['db_backup_last_backup']) + 60 * 60 * $config['db_backup_time'])) < ($current_time)){ // <
$backup_time = format_date($config['date_format']." ".$config['time_format'], $current_time);
$backup_ok = makebackup($current_time);
if($backup_ok){
$sql = "UPDATE ".SETTINGS_TABLE."
SET setting_value = '$backup_time'
WHERE setting_name = 'db_backup_last_backup'";
}
$result = $site_db->query($sql);
}
return $backup_ok;
}
5.) search in includes/page_header.php:
//-----------------------------------------------------
//--- User Box ----------------------------------------
insert above:
if($config['db_backup_time'] > 0){
$event_user_id = explode(",",$config['db_backup_event']);
if (in_array($user_info['user_id'], $event_user_id)){
$current_time = time();
$backup_ok = startbackup($current_time);
$msg = ($backup_ok) ? $lang['db_backup_done']:"";
}
}
6.) search in root/global.php:
define('ICON_PATH', ROOT_PATH.TEMPLATE_DIR."/".$config['template_dir']."/icons");
insert below:
define('EMAIL_PATH', ROOT_PATH."lang/".$config['language_dir']."/email");
6.1) search:
$site_template = new Template(TEMPLATE_PATH);
insert below:
$site_mailtemplate = new Template(EMAIL_PATH);
mfg Andi