* @since 1.0.0 **/ class backup extends admin { /** * Database backup * * @author Aaron Smith-Hayes * @since 1.0.0 * @return string HTML **/ function execute() { if (!isset($this->get['s'])) { $this->get['s'] = ''; } switch($this->get['s']) { case 'create': $this->set_title($this->lang->backup_create); $this->tree($this->lang->backup_create); return $this->create_backup(); break; case 'restore': $this->set_title($this->lang->backup_restore); $this->tree($this->lang->backup_restore); return $this->restore_backup(); break; } } /** * Generate a backup * * @author Aaron Smith-Hayes * @since 1.0.0 * @return string HTML **/ function create_backup() { if(!isset($this->post['submit'] ) ) return eval($this->template('ADMIN_BACKUP')); $filename = "backup_".$this->version."-".date('y-m-d-H-i-s').".sql"; $options = ''; foreach($this->post as $key => $value ) $$key = $value; if(isset($insert)) $options .= ' -c'; if(isset($droptable)) $options .= ' --add-drop-table'; $tables = implode( ' ', $this->get_db_tables() ); $mbdump = "mysqldump ".$options." --password=".$this->db->pass." --host=".$this->db->host." --user=".$this->db->user; $mbdump .= " --result-file='../packages/".$filename."' ".$this->db->db." ".$tables; if( ($fp = popen($mbdump, 'r') ) === false ) return $this->message($this->lang->backup_create, $this->lang->backup_failed); $buf = ''; while( $c = fgetc($fp) ) $buf .= $c; pclose($fp); $this->chmod('../packages/'.$filename, 0777); return $this->message($this->lang->backup_create, $this->lang->backup_created ." ../packages/".$filename."
". $this->lang->backup_output .": ".$buf, $filename, "../packages/".$filename); } /** * Restore a backup * * @author Aaron Smith-Hayes * @since 1.0.0 * @return string HTML **/ function restore_backup() { if (!isset($this->get['restore'])) { if ( ($dir = opendir('../packages') ) === false ) return $this->message($this->lang->backup_restore, $this->lang->backup_no_packages); $backups = array(); while( ($file = readdir($dir) ) ) { if(strtolower(substr($file, -4) ) != '.sql') continue; $backups[] = $file; } closedir($dir); if(count($backups) <= 0 ) return $this->message($this->lang->backup_restore, $this->lang->backup_none); $output = $this->lang->backup_warning . '

'; $output .= $this->lang->backup_found . ':

'; $count = 0; foreach( $backups as $bkup ) { $output .= "".$bkup."
"; } return $this->message($this->lang->backup_restore, $output); } if(!file_exists('../packages/' . $this->get['restore']) ) return $this->message($this->lang->backup_restore, $this->lang->backup_noexist); $mbimport = "mysql --password=".$this->db->pass." --host=".$this->db->host." --user=".$this->db->user." ".$this->db->db." < ../packages/".$this->get['restore']; if( ($fp = popen($mbimport, 'r') ) === false ) return $this->message($this->lang->backup_restore, $this->lang->backup_import_fail); $output = ''; while($c = fgetc($fp) ) $output .= $c; return $this->message($this->lang->backup_restore, $this->lang->backup_restore_done ."
". $this->lang->backup_output .": ".$output); } } ?>