Detail: This MOD like
http://www.4homepages.de/forum/index.php?topic=15095.0 but better. No system command use (linux) and cron work on user visit (guest include) for 4images. 50% Jan module for DB utils and 50% use for new ZIP module improve. You can choose (1 day minumum) for how day wait for backup process and send email message for say is backup on server in BACKUP_DIR folder.
All admin receive email (allow email use or no work for them) for time you set.
Require:
-
GZip, ZIP or BZip enable from host or no work.
- ZIP improve:
http://www.4homepages.de/forum/index.php?topic=18745.0- HTML Email:
http://www.4homepages.de/forum/index.php?topic=18744.0// Step 1
In includes/functions.php file,
add top ?>:
function backup_site_operation() {
global $user_info, $site_db, $lang, $config, $site_template, $url, $db_name, $default_backup_tables;
if (!isset($config['backup_site_next_time'])) {
$site_db->query("INSERT INTO " . SETTINGS_TABLE . " (setting_name, setting_value) VALUES ('backup_site_next_time', '" . time() . "')");
}
$check_next_time = time() - 60 * 60 * 24 * BACKUP_SITE_DAYS_DELAY;
$backup_archive_name = ROOT_PATH . BACKUP_DIR . "/backup.zip";
$debug_id = (defined('BACKUP_SITE_DEBUG_ID') && $user_info['user_level'] == ADMIN && $user_info['user_id'] == BACKUP_SITE_DEBUG_ID) ? true : false;
if ($check_next_time >= $config['backup_site_next_time'] || !@file_exists($backup_archive_name) || (isset($debug_id) && $debug_id) && $user_info['user_id'] == $debug_id) {
@include_once(ROOT_PATH . "includes/db_utils.php");
$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 ".format_text($config['site_name'], 2).$crlf;
echo "# ".date("Y-m-d H:i").$crlf;
echo "#----------------------------------------------------------".$crlf;
foreach ($default_backup_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 = "backup".time().".sql.gz";
$fp = @gzopen(ROOT_PATH.DATABASE_DIR."/".$file_name, "w9");
$ok = @gzwrite($fp, $contents);
gzclose($fp);
}
else {
$file_name = "backup".date("YmdHi").".sql";
$fp = @fopen(ROOT_PATH.DATABASE_DIR."/".$file_name, "w");
$ok = @fwrite($fp, $contents);
fclose($fp);
}
include(ROOT_PATH . "includes/archive.php");
$backup_operation = new zip_file($backup_archive_name);
$backup_operation->set_options(array('inmemory' => 0, 'recurse' => 1, 'storepaths' => 1, 'overwrite' => 1));
$backup_operation->add_files(ROOT_PATH);
$backup_operation->exclude_files(ROOT_PATH . "data/backup");
$backup_operation->exclude_files(ROOT_PATH . "data/database/default");
$backup_operation->create_archive();
$backup_operation->download_file();
if (count($backup_operation->errors) <= 0) {
if ($user_info['user_level'] == ADMIN) {
echo $lang['backup_site_create_success'] . "<br />";
}
@unlink(ROOT_PATH.DATABASE_DIR."/".$file_name);
@include_once(ROOT_PATH . 'includes/html_email/MAIL.php');
// get ID value (random) for the embed image
$id = MIME::unique();
$site_email = new MAIL;
$sql1 = "
SELECT " . get_user_table_field("", "user_name") . get_user_table_field(", ", "user_email") . "
FROM " . USERS_TABLE . "
WHERE " . get_user_table_field("", "user_level") . " >= '" . ADMIN . "' AND " . get_user_table_field("", "user_allowemails") . " = 1 AND " . get_user_table_field("", "user_id") . " != " . $user_info['user_id'];
$result1 = $site_db->query($sql1);
$site_email->From(stripslashes($config['site_email']), format_text($config['site_name'], 2));
if ($user_info['user_level'] == ADMIN && isset($user_info['user_email'])) {
$site_email->AddTo(stripslashes($user_info['user_email']), format_text(trim($user_info['user_name']), 2));
} else {
$site_email->AddTo(stripslashes($config['site_email']), format_text($config['site_name'], 2));
}
$email_row = array();
while ($row = $site_db->fetch_array($result1)) {
$email_row[] = $row;
}
$site_db->free_result($result1);
$num_email = sizeof($email_row);
$user_name = "";
$user_email = "";
for ($i = 0; $i < $num_email; $i++) {
if ((function_exists('mailchek') && mailchek($email_row[$i][$user_table_fields['user_email']], 2)) || (FUNC::is_mail($email_row[$i][$user_table_fields['user_email']], true)) && !preg_match("/([\msn|yahoo|caramail|incredimail]+[\.]+[\com|net|ca|org|de|ru|sh|se|fr|au]+)/i", $email_row[$i][$user_table_fields['user_email']])) {
$user_name = $email_row[$i][$user_table_fields['user_name']];
$user_email = $email_row[$i][$user_table_fields['user_email']];
if (isset($user_name) && !empty($user_name) && isset($user_email) && !empty($user_email) && !isset($user_info['user_name'])) {
$site_email->Text(str_replace(array("{site_name}", "{ftp_location}", "{user_name}", "{delay_time}"), array(format_text($config['site_name'], 2), format_text(stripslashes(trim($backup_archive_name)), 2), format_text(trim($user_name), 2), (int)BACKUP_SITE_DAYS_DELAY), $lang['backup_site_notify_text_message']));
$site_email->Cc[] = array(
'address' => stripslashes($user_email), // required
'name' => format_text(trim($user_name), 2), // optional
'charset' => $lang['charset'], // optional
'encoding' => 'base64' // optional
);
}
}
}
$site_email->Subject(preg_replace("/" . $site_template->start . "site_name" . $site_template->end . "/siU", format_text($config['site_name'], 2), $lang['backup_site_notify_subject_title']));
if ($user_info['user_name']) {
$site_email->Text(str_replace(array("{site_name}", "{ftp_location}", "{user_name}", "{delay_time}"), array(format_text($config['site_name'], 2), format_text(stripslashes(trim($backup_archive_name)), 2), format_text(trim($user_info['user_name']), 2), BACKUP_SITE_DAYS_DELAY), $lang['backup_site_notify_text_message']));
}
if ($user_info['user_level'] == ADMIN) {
echo $site_email->Send('client') ? preg_replace("/" . $site_template->start . "delay_time" . $site_template->end . "/siU", (int)BACKUP_SITE_DAYS_DELAY, $lang['backup_site_mail_sent']) : $lang['backup_site_mail_error'];
}
$site_email->Delto();
$site_email->Delcc();
$site_email->DelAttach();
$site_email->Disconnect();
unset ($email_row);
unset ($user_name);
unset ($user_email);
$site_db->query("UPDATE " . SETTINGS_TABLE . " SET setting_value = '" . time() . "' WHERE setting_name = 'backup_site_next_time'");
} elseif (count($backup_operation->errors) > 0) {
echo $lang['backup_site_create_fail'];
}
}
} // End function.
In includes/constants.php file,
find:
define('DATABASE_DIR', 'data/database');
add after:
define('BACKUP_DIR', 'data/backup'); // Change folder name !!! (backup to something else)
Change folder name ! (FTP / File manager and define). After, set CHMOD 777 to folder.
Add top ?>:
define('BACKUP_SITE_DAYS_DELAY', 1); // Set to 1 day.
//define('BACKUP_SITE_DEBUG_ID', 1); // Debug Admin ID
Is here you can set BACKUP_SITE_DAYS_DELAY (is
1 for now for 1 day). If want more (ex: 3 day - remove 1 and set 3). 3 days, ZIP file will create.
BACKUP_SITE_DEBUG_ID is for debug. 1 is user ID. If need, remove // and replace for done.
// Step 3
In includes/page_header.php file,
find:
//-----------------------------------------------------
//--- Random Image ------------------------------------
//-----------------------------------------------------
add before:
//-----------------------------------------------------
//--- Backup site -------------------------------------
//-----------------------------------------------------
if (function_exists('backup_site_operation')) {
backup_site_operation();
}
// Step 4
In lang/english/main.php file,
add top ?>:
$lang['backup_site_create_success'] = "<span class=\"smalltext\"><font color=\"green\">Done !</font></span>";
$lang['backup_site_create_fail'] = "<span class=\"smalltext\"><font color=\"red\">Fail !</font></span>";
$lang['backup_site_notify_subject_title'] = "Backup site for: {site_name}";
$lang['backup_site_notify_text_message'] = "Dear {user_name}, \n\n{site_name} has just performed a backup operation of the entire 4images folder on a ZIP file.\nThe File is located in: {ftp_location} (SQL file included).\n\nThis message will appear every {delay_time} day(s).\n\nRegards.\n{site_name}";
$lang['backup_site_list_title'] = "Backup Gallery List";
$lang['backup_site_list_do_backup'] = "Gallery Backup";
$lang['backup_site_list_backup_success'] = "Gallery backed up.";
$lang['backup_site_list_backup_error'] = "<span class=\"smalltext\"><font color=\"red\">Gallery not backed up.</font></span>";
$lang['backup_site_mail_sent'] = "Email sent !<br />Next backup in: <b>{delay_time}</b> day(s).<br />";
$lang['backup_site_mail_error'] = "Error while sending email. Please check mail / web logs (cPanel access) and post in 4homepages.de forum - official topic - if need help.";
// Step 5
Download backup.zip file attachment. Replace admin/backup.php file (or compare if use other MOD on forum - I give no support for compare).
// Step 6
Go to ACP -> Backup database. Should see new window.
// Step 7 (
09/19/2007)
In includes/db_field_definitions.php file,
$default_backup_tables = array(
table1,
table2
);
Replace:
table1,
table2 with
all define table you have (only define name) from includes/constants.php file.
Should work (use ACP - > setting for email address too).