Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $aksi=isset($_GET['aksi']) ? $_GET['aksi'] : "";
- switch($aksi){
- default:
- $waktu=date("DdMY");
- echo"<div class='content_block'><div class='box_bg'><h2>Backup Database</div></div><div class='content_block'><div class='box_bg'>";
- if(!isset($_GET['tabel']))$tables='semua';
- else $tables=$_GET['tabel'];
- if($tables == 'semua'){
- $tables = array();
- $result = mysql_query('SHOW TABLES');
- while($row = mysql_fetch_row($result)){
- $tables[] = $row[0];
- $return.= 'DROP TABLE IF EXIST IF EXIST '.$table.';';}
- }else{
- //jika hanya table-table tertentu
- $tables = is_array($tables) ? $tables : explode(',',$tables);
- }
- //looping dulu ah
- $return="";
- foreach($tables as $table){
- $result = mysql_query('SELECT * FROM '.$table);
- $num_fields = mysql_num_fields($result);
- //menyisipkan query DROP TABLE IF EXIST untuk nanti hapus table yang lama
- $return.= 'DROP TABLE IF EXIST '.$table.';';
- $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
- $return.= "".$row2[1].";";
- for ($i = 0; $i < $num_fields; $i++){
- while($row = mysql_fetch_row($result)){
- /*
- menyisipkan query Insert. untuk nanti memasukan data yang lama ketable yang baru dibuat. so toy mode : ON
- */
- $return.= 'INSERT INTO '.$table.' VALUES(';
- for($j=0; $j<$num_fields; $j++){
- //akan menelusuri setiap baris query didalam
- $row[$j] = $row[$j];
- if (isset($row[$j])) {
- $return.= '"'.addslashes($row[$j]).'"' ;
- }
- else {
- $return.= '""';
- }
- if ($j<($num_fields-1)) {
- $return.= ',';
- }
- }
- $return.= ");\n";
- }
- }
- $return.="\n\n";
- }
- $tabel=array("ppdb_admin", "ppdb_pendaftar", "ppdb_info","ppdb_kontak","ppdb_menu","ppdb_submenu","ppdb_siswa","ppdb_clnsiswa","ppdb_prestasi","ppdb_nilai");
- echo"<form name='form-backup' method='post' action='?module=backup&aksi=backup'>
- Pilih tabel <select name='tabel' onChange=\"window.location.href='?module=backup&tabel='+this.value;\">
- <option value='semua'>semua tabel</option>";
- $table=isset($_GET['tabel']) ? $_GET['tabel'] : "semua";
- foreach($tabel as $tbl){
- echo"<option value='$tbl'";
- if($tbl==$table) echo" selected";
- echo">$tbl</option>";
- }
- echo "</select>
- <textarea name='isitabel' style='width: 100%;' cols=83 rows=25>".htmlentities($return)."</textarea><br>
- <input type=submit class='tombol' value='Backup'></form>";
- echo"</div></div>";
- break;
- case "backup":
- $nama_file=date("DdMY").'_backup_data_'.time().'.sql';
- $return=$_POST['isitabel'];
- $nama_file;
- $handle = fopen('backup/'.$nama_file,'w+');
- fwrite($handle, stripslashes($return) );
- fclose($handle);
- echo "Database berhasil dibackup, untuk mendownload file backup klik tombol berikut!<br><br>
- <a class='tombol' href='modul/mod_br/backup/backup.php?aksi=download&file=$nama_file'>Download File Backup</a>";
- break;
- case "download":
- $folder="../../../backup/";
- $file=$_GET['file'];
- header("Content-Disposition: attachment; filename=$folder".$file);
- header("Content-type: $folder".$file);
- readfile("$folder".$file);
- unlink("$folder$file");
- exit;
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement