Changeset 2577
- Timestamp:
- 02/06/10 08:51:44 (6 weeks ago)
- Location:
- branches/backup-restore
- Files:
-
- 6 modified
-
backup.php (modified) (3 diffs)
-
includes/BackupPackage.php (modified) (4 diffs)
-
includes/BackupPackage_ispCP.php (modified) (6 diffs)
-
includes/Base.php (modified) (2 diffs)
-
includes/RestorePackage_ispCP.php (modified) (5 diffs)
-
restore.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/backup-restore/backup.php
r2562 r2577 26 26 echo "OPTIONS:\n"; 27 27 echo " -v ........... verbose mode\n"; 28 echo "\n"; 29 echo "Please ensure, there is enough free disk space available for\n"; 30 echo "this operation (approx. triple size of htdocs and databases)!\n"; 28 31 exit(1); 29 32 } … … 38 41 $domain_name = $argv[$argc-2]; 39 42 $password = $argv[$argc-1]; 40 if (!file_exists(ISPCP_VIRTUAL_PATH.'/'.$domain_name)) {41 echo "Domain not found in ".ISPCP_VIRTUAL_PATH.'/'.$domain_name."\n";42 exit(2);43 }44 45 // make clean temp path for every call46 if (file_exists(BACKUP_TEMP_PATH)) {47 delTree(BACKUP_TEMP_PATH);48 }49 mkdir(BACKUP_TEMP_PATH, 0700, true);50 51 // create archive path if not exist52 if (!file_exists(ARCHIVE_PATH)) {53 mkdir(ARCHIVE_PATH, 0700, true);54 }55 43 56 44 $exitcode = 0; … … 68 56 } 69 57 70 // clean up temp path on exit71 if (file_exists(BACKUP_TEMP_PATH)) {72 delTree(BACKUP_TEMP_PATH);73 }74 75 58 exit($exitcode); -
branches/backup-restore/includes/BackupPackage.php
r2576 r2577 44 44 public function __construct($domain_name, $password) 45 45 { 46 // make clean temp path for every call 47 if (file_exists(BACKUP_TEMP_PATH)) { 48 delTree(BACKUP_TEMP_PATH); 49 } 50 mkdir(BACKUP_TEMP_PATH, 0700, true); 51 52 // create archive path for domain packages if not exist 53 if (!file_exists(ARCHIVE_PATH)) { 54 mkdir(ARCHIVE_PATH, 0700, true); 55 } 56 46 57 $this->password = $password; 47 58 $this->domain_name = $domain_name; 59 60 // tar and mysqldump can take a lot of time 61 set_time_limit(0); 62 } 63 64 /** 65 * Destructor, clean up temp path on exit 66 */ 67 public function __destruct() 68 { 69 if (file_exists(BACKUP_TEMP_PATH)) { 70 delTree(BACKUP_TEMP_PATH); 71 } 48 72 } 49 73 … … 111 135 * Create .tar.gz and protect by gpg symmetric encryption 112 136 */ 113 private function createDomain Archive()137 private function createDomainPackage() 114 138 { 115 139 // create .tar.gz … … 128 152 $this->shellExecute($cmd, $a); 129 153 130 // delete .tar.gz154 // delete remaining .tar.gz 131 155 unlink($filename); 132 156 … … 152 176 $this->setConfigData('dbuser', $this->getDBUserConfig()); 153 177 154 // first create configuration file155 // if successful, create databases and complete domain archive178 // First create configuration file. If successful, create database 179 // dumps and create the complete domain package file 156 180 $result = $this->writeDomainConfig(); 157 181 if ($result) { 158 182 $result = $this->dumpDomainDatabases(); 159 183 if ($result) { 160 $result = $this->createDomain Archive();184 $result = $this->createDomainPackage(); 161 185 } 162 186 } -
branches/backup-restore/includes/BackupPackage_ispCP.php
r2570 r2577 39 39 * ispCP database IDs (name => id) 40 40 */ 41 pr ivate$db_ids = array();41 protected $db_ids = array(); 42 42 43 43 public function __construct($domain_name, $password) … … 47 47 } 48 48 49 /** 50 * Get domain database id, validate if vhost path exists 51 * @return bool true = init ok, false = see error message 52 */ 49 53 protected function initDomain() 50 54 { 51 55 $result = false; 52 56 53 $test = $this->getDomainID($this->domain_name); 54 if ($test != -1) { 55 $result = true; 57 if (!file_exists(ISPCP_VIRTUAL_PATH.'/'.$this->domain_name)) { 58 $this->addErrorMessage('Domain not found in '.ISPCP_VIRTUAL_PATH.'/'.$this->domain_name); 56 59 } else { 57 $this->addErrorMessage('Domain not in database: '.$this->domain_name); 60 $test = $this->getDomainID($this->domain_name); 61 if ($test != -1) { 62 $result = true; 63 } else { 64 $this->addErrorMessage('Domain not in database: '.$this->domain_name); 65 } 58 66 } 59 67 … … 66 74 * @return integer domain id, -1 if not present 67 75 */ 68 pr ivatefunction getDomainID($domain_name)76 protected function getDomainID($domain_name) 69 77 { 70 78 $this->domain_id = -1; … … 148 156 $rs = $this->db->Execute($query, array(':id'=>$this->domain_id)); 149 157 while (!$rs->EOF) { 150 // TODO: sub_id?151 158 $row = $rs->FetchRow(); 152 159 $row['mail_pass'] = decrypt_db_password($row['mail_pass']); … … 172 179 $rs = $this->db->Execute($query, array(':uid'=>$this->domain_user_id)); 173 180 while ($rs && !$rs->EOF) { 174 // TODO: passwd? Where is the magic?175 181 $row = $rs->FetchRow(); 176 182 $result[] = $row; … … 205 211 } 206 212 207 pr ivatefunction getSubdomainAliasConfig($alias_id)213 protected function getSubdomainAliasConfig($alias_id) 208 214 { 209 215 $result = array(); -
branches/backup-restore/includes/Base.php
r2562 r2577 25 25 public $verbose = false; 26 26 /** 27 * array of error messages27 * array of strings for error messages 28 28 */ 29 29 protected $errorMessages = array(); … … 55 55 } 56 56 } 57 -
branches/backup-restore/includes/RestorePackage_ispCP.php
r2570 r2577 19 19 */ 20 20 21 /** 22 * ispCP restore packager main class 23 */ 21 24 class RestorePackage_ispCP extends BaseController 22 25 { … … 42 45 protected $ip_id = -1; 43 46 /** 47 * Reseller name or false for first reseller 48 */ 49 protected $reseller; 50 /** 51 * ID of reseller 52 */ 53 protected $reseller_id = -1; 54 /** 44 55 * linux user id 45 56 */ 46 57 protected $domain_user_id = 0; 47 48 public function __construct($domain_name, $password, $specific_ip) 58 /** 59 * file name of gpg encrypted domain package 60 */ 61 protected $archive = ''; 62 63 /** 64 * Restore packager 65 * @param string $domain_name 66 * @param string $password password for gpg symmetric decryption 67 * @param mixed $option_ip false or string of target IP address 68 * @param mixed $option_reseller false or string of reseller name 69 */ 70 public function __construct($domain_name, $password, $option_ip, $option_reseller) 49 71 { 50 72 $this->password = $password; 51 73 $this->domain_name = $domain_name; 52 74 $this->db = Database::getInstance(); 53 $this->ip = $specific_ip; 54 } 55 56 private function setDomainPermissions() 75 $this->ip = $option_ip; 76 $this->reseller = $option_reseller; 77 $this->archive = ARCHIVE_PATH.'/'.$this->domain_name.'.tar.gz.gpg'; 78 79 // untar and mysql can take a lot of time 80 set_time_limit(0); 81 } 82 83 /** 84 * Set permissions to vhost directory 85 */ 86 protected function setDomainPermissions() 57 87 { 58 88 // TODO: setDomainPermissions (chown) … … 63 93 * @return integer ID of IP 64 94 */ 65 pr ivate function getDefaultIP()95 protected function getDefaultIPID() 66 96 { 67 97 $result = -1; … … 80 110 81 111 /** 82 * Get ID of specific IP 112 * Get ID of first reseller 113 * @return integer ID of reseller 114 */ 115 protected function getDefaultResellerID() 116 { 117 $result = -1; 118 119 $sql = "SELECT `admin_id` FROM `admin` WHERE `admin_type` = :admin_type" . 120 " ORDER BY `admin_id` LIMIT 0, 1"; 121 $query = $this->db->Prepare($sql); 122 $rs = $this->db->Execute($query, array(':admin_type'=>'reseller')); 123 if ($rs && !$rs->EOF) { 124 $result = $rs->fields['admin_id']; 125 } else { 126 $this->addErrorMessage('No resellers found!?'); 127 } 128 129 return $result; 130 } 131 132 /** 133 * Get ID of reseller name 134 * @param string $reseller name of reseller (e.g. 'res1') 135 * @return integer ispCP database ID of reseller 136 */ 137 protected function getResellerID($reseller) 138 { 139 $result = -1; 140 141 $sql = "SELECT `admin_id` FROM `admin` WHERE `admin_type` = :admin_type" . 142 " AND `admin_name` = :name" . 143 " ORDER BY `admin_id` LIMIT 0, 1"; 144 $query = $this->db->Prepare($sql); 145 $rs = $this->db->Execute($query, array(':admin_type'=>'reseller', ':name'=>$reseller)); 146 if ($rs && !$rs->EOF) { 147 $result = $rs->fields['admin_id']; 148 } else { 149 $this->addErrorMessage('Reseller not found: '.$reseller); 150 } 151 152 return $result; 153 } 154 155 /** 156 * Get ID of IP 83 157 * @param string $ip IP address 84 * @return integer ID of IP85 */ 86 pr ivate function getSpecificIP($ip)158 * @return integer ispCP database ID of IP 159 */ 160 protected function getIPID($ip) 87 161 { 88 162 $result = -1; … … 94 168 $result = $rs->fields['ip_id']; 95 169 } else { 96 $this->addErrorMessage('IP not found!?'); 97 } 98 99 return $result; 100 } 101 170 $this->addErrorMessage('IP not found: '.$ip); 171 } 172 173 return $result; 174 } 175 176 /** 177 * Validate presence of gpg encrypted archive, get ID of IP and reseller 178 */ 179 protected function initRestore() 180 { 181 $result = false; 182 183 if (!file_exists($this->archive)) { 184 $this->addErrorMessage('Domain backup package file not found: '.$this->archive); 185 } else { 186 // IP detection 187 if ($this->ip === false) { 188 $this->ip_id = $this->getDefaultIPID(); 189 } else { 190 $this->ip_id = $this->getIPID($this->ip); 191 } 192 193 // Reseller detection 194 if ($this->reseller === false) { 195 $this->reseller_id = $this->getDefaultResellerID(); 196 } else { 197 $this->reseller_id = $this->getResellerID($this->reseller); 198 } 199 200 if ($this->ip_id != -1 && $this->reseller_id != -1) { 201 $result = true; 202 } 203 } 204 205 return $result; 206 } 207 208 /** 209 * Run the restore, main method 210 * @return boolean true = restore successful, false = see error messages 211 */ 102 212 public function runRestore() 103 213 { 104 214 $result = false; 105 215 106 // IP detection 107 if ($this->ip === false) { 108 $this->ip_id = $this->getDefaultIP(); 109 } else { 110 $this->ip_id = $this->getSpecificIP($this->ip); 111 } 112 113 if ($this->ip_id != -1) { 114 // TODO: got IP ID, go on... 216 if ($this->initRestore()) { 217 // TODO: runRestore() 218 // don't forget sub_id in mail accounts! 115 219 } 116 220 -
branches/backup-restore/restore.php
r2570 r2577 25 25 echo "Usage: php restore.php [OPTIONS] domain archive-password\n"; 26 26 echo "OPTIONS:\n"; 27 echo " -i IP ........ use specific IP for domain\n"; 27 echo " -i IP ........ use IP for domain (default = first found)\n"; 28 echo " -r RES ....... use reseller for domain (default = first found)\n"; 28 29 echo " -v ........... verbose mode\n"; 30 echo "\n"; 31 echo "Please ensure, there is enough free disk space available for\n"; 32 echo "this operation (approx. triple size of htdocs and databases)!\n"; 29 33 exit(1); 30 34 } 31 35 32 $verbose = $ specific_ip= false;36 $verbose = $option_ip = $option_res = false; 33 37 for ($i = 1; $i < $argc-2; $i++) { 34 38 if ($argv[$i] == '-v') { 35 39 $verbose = true; 36 40 } elseif ($argv[$i] == '-i') { 37 $specific_ip = $argv[++$i]; 41 $option_ip = $argv[++$i]; 42 } elseif ($argv[$i] == '-r') { 43 $option_res = $argv[++$i]; 38 44 } 39 45 } … … 41 47 $domain_name = $argv[$argc-2]; 42 48 $password = $argv[$argc-1]; 43 if (!file_exists(ARCHIVE_PATH.'/'.$domain_name.'.tar.gz.gpg')) {44 echo "Domain backup file not found in ".ARCHIVE_PATH.'/'.$domain_name.'.tar.gz.gpg'."\n";45 exit(2);46 }47 49 48 50 $exitcode = 0; 49 $handler = new RestorePackage_ispCP($domain_name, $password, $ specific_ip);51 $handler = new RestorePackage_ispCP($domain_name, $password, $option_ip); 50 52 $handler->verbose = $verbose; 51 53 if ($handler->runRestore() == false) {
