From 49029cc4c2cdaa7505430f77e0492d2c91cd1da2 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 01 Jul 2010 10:26:24 -0400
Subject: [PATCH] Implemented the server part for FS#759 - Website Account Backup
---
server/cron_daily.php | 66 +++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/server/cron_daily.php b/server/cron_daily.php
index 27d522e..5b80105 100644
--- a/server/cron_daily.php
+++ b/server/cron_daily.php
@@ -371,6 +371,72 @@
}
+#######################################################################################################
+// Create website backups
+#######################################################################################################
+
+$server_config = $app->getconf->get_server_config($conf["server_id"], 'server');
+$backup_dir = trim($server_config['backup_dir']);
+
+if($backup_dir != '') {
+
+ if(!is_dir($backup_dir)) {
+ exec("mkdir -p ".escapeshellarg($backup_dir));
+ }
+
+ $sql = "SELECT * FROM web_domain WHERE type = 'vhost'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+
+ // Create a backup
+ if($rec['backup_interval'] == 'daily' or ($rec['backup_interval'] == 'daily' && date('w') == 0) or ($rec['backup_interval'] == 'monthly' && date('d') == '01')) {
+
+ $web_path = $rec['document_root'];
+ $web_user = $rec['system_user'];
+ $web_group = $rec['system_group'];
+ $web_id = $rec['domain_id'];
+ $web_backup_dir = $backup_dir.'/web'.$web_id;
+ if(!is_dir($web_backup_dir)) mkdir($web_backup_dir);
+
+ exec('chown root:root '.$web_backup_dir);
+ exec('chmod 755 '.$web_backup_dir);
+ exec("cd ".escapeshellarg($web_path)." && sudo -u ".escapeshellarg($web_user)." find . -group ".escapeshellarg($web_group)." -print | zip -y ".escapeshellarg($web_backup_dir."/web.zip")." -@");
+
+ // Rename or remove old backups
+ $backup_copies = intval($rec['backup_copies']);
+
+ if(is_file($web_backup_dir."/web.".$backup_copies.".zip")) unlink($web_backup_dir."/web.".$backup_copies.".zip");
+
+ for($n = $backup_copies - 1; $n >= 1; $n--) {
+ if(is_file($web_backup_dir."/web.".$n.".zip")) {
+ rename($web_backup_dir."/web.".$n.".zip",$web_backup_dir."/web.".($n+1).".zip");
+ }
+ }
+
+ if(is_file($web_backup_dir."/web.zip")) rename($web_backup_dir."/web.zip",$web_backup_dir."/web.1.zip");
+
+ // Create backupdir symlink
+ if(is_link($web_path.'/backup')) unlink($web_path.'/backup');
+ symlink($web_backup_dir,$web_path.'/backup');
+
+ }
+
+ /* If backup_interval is set to none and we have a
+ backup directory for the website, then remove the backups */
+
+ if($rec['backup_interval'] == 'none') {
+ $web_id = $rec['domain_id'];
+ $web_user = $rec['system_user'];
+ $web_backup_dir = realpath($backup_dir.'/web'.$web_id);
+ if(is_dir($web_backup_dir)) {
+ exec("sudo -u ".escapeshellarg($web_user)." rm -f ".escapeshellarg($web_backup_dir.'/*'));
+ }
+ }
+ }
+ }
+}
+
die("finished.\n");
?>
\ No newline at end of file
--
Gitblit v1.9.1