-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbackup.php
129 lines (114 loc) · 6.38 KB
/
backup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
//cek session
if(empty($_SESSION['admin'])){
$_SESSION['err'] = '<center>Anda harus login terlebih dahulu!</center>';
header("Location: ./");
die();
} else {
if($_SESSION['admin'] != 1){
echo '<script language="javascript">
window.alert("ERROR! Anda tidak memiliki hak akses untuk membuka halaman ini");
window.location.href="./logout.php";
</script>';
} else {
echo '<!-- Row Start -->
<div class="row">
<!-- Secondary Nav START -->
<div class="col s12">
<div class="z-depth-1">
<nav class="secondary-nav">
<div class="nav-wrapper blue-grey darken-1">
<div class="col m12">
<ul class="left">
<li class="waves-effect waves-light"><a href="?page=sett&sub=back" class="judul"><i class="material-icons">storage</i> Backup Database</a></li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<!-- Secondary Nav END -->
</div>
<!-- Row END -->';
// download file hasil backup
if(isset($_REQUEST['nama_file'])){
$back_dir = "backup/";
$file = $back_dir.$_REQUEST['nama_file'];
$x = explode('.', $file);
$eks = strtolower(end($x));
if($eks == 'sql'){
if(file_exists($file)){
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: private');
header('Pragma: private');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
} else {
echo '<script language="javascript">
window.alert("ERROR! File sudah tidak ada");
window.location.href="./admin.php?page=sett&sub=back";
</script>';
}
} else {
if($_SESSION['id_user'] == 1){
echo '<script language="javascript">
window.alert("ERROR! Format file yang boleh didownload hanya *.SQL");
window.location.href="./logout.php";
</script>';
}
}
}
// proses backup database dilakukan oleh Fungsi
//nama database hasil backup
$file = date("Y-m-d_His").'.sql';
//backup database
if(isset($_REQUEST['backup'])){
//konfigurasi backup database: host, user, password, database
backup($host, $username, $password, $database, $file, "*");
echo '<!-- Row form Start -->
<div class="row">
<div class="col m12">
<div class="card">
<div class="card-content">
<span class="card-title black-text"><div class="confirr green-text"><i class="material-icons md-36">done</i>
SUKSES! Database berhasil dibackup</div></span>
<p class="kata" style="margin-top: 10px;">Silakan klik tombol <strong>"Download"</strong> dibawah ini untuk mendownload file backup database.</p>
</div>
<div class="card-action">
<form method="post" enctype="multipart/form-data" >
<a href="?page=sett&sub=back&nama_file='.$file.'" class="btn-large blue waves-effect waves-light white-text">DOWNLOAD <i class="material-icons">file_download</i></a>
</form>
</div>
</div>
</div>
</div>';
} else {
echo '
<!-- Row form Start -->
<div class="row">
<div class="col m12">
<div class="card">
<div class="card-content">
<span class="card-title black-text">Backup Database</span>
<p class="kata">Lakukan backup database secara berkala untuk membuat cadangan database yang bisa direstore kapan saja ketika dibutuhkan. Silakan klik tombol <strong>"Backup"</strong> untuk memulai proses backup data. Setelah proses backup selesai, silakan download file backup database tersebut dan simpan di lokasi yang aman.<span class="red-text"><strong>*</strong></span></p><br/>
<p><span class="red-text"><strong>*</strong></span> Tidak disarankan menyimpan file backup database dalam my documents / Local Disk C.</p>
</div>
<div class="card-action">
<form method="post" enctype="multipart/form-data" >
<button type="submit" class="btn-large blue waves-effect waves-light" name="backup">BACKUP <i class="material-icons">backup</i></button>
</form>
</div>
</div>
</div>
</div>';
}
}
}
?>