PluginProbe
WP-DBManager / 2.04
WP-DBManager v2.04
4.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.65 2.70 2.71 2.72 2.73 2.74 2.75 2.76 2.78 All 40 releases
wp-dbmanager / dbmanager / database-backup.php

database-backup.php in WP-DBManager 2.04, at dbmanager/database-backup.php

195 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 | |
5 | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6 | Copyright (c) 2005 Lester "GaMerZ" Chan |
7 | |
8 | File Written By: |
9 | - Lester "GaMerZ" Chan |
10 | - http://www.lesterchan.net |
11 | |
12 | File Information: |
13 | - Database Backup |
14 | - wp-content/plugins/dbmanager/database-backup.php |
15 | |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Require Database Config
21 require('database-config.php');
22
23 ### Form Processing
24 if($_POST['do']) {
25 // Decide What To Do
26 switch($_POST['do']) {
27 case 'Backup':
28 $gzip = intval($_POST['gzip']);
29 if($gzip == 1) {
30 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
31 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
32 $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
33 } else {
34 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
35 $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
36 $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
37 }
38 passthru($backup['command'], $error);
39 if(!is_writable($backup['path'])) {
40 $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Backup Folder Not Writable.</font>";
41 } elseif(filesize($backup['filepath']) == 0) {
42 unlink($backup['filepath']);
43 $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Backup File Size Is 0KB.</font>";
44 } elseif(!is_file($backup['filepath'])) {
45 $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Invalid Backup File Path.</font>";
46 } elseif($error) {
47 $text = "<font color=\"red\">Database Failed To Backup On '$current_date'.</font>";
48 } else {
49 $text = "<font color=\"green\">Database Backed Up Successfully On '$current_date'.</font>";
50 }
51 break;
52 }
53 }
54
55
56 ### Backup File Name
57 $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
58
59
60 ### MYSQL Base Dir
61 $mysql_basedir = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
62 $mysql_basedir = $mysql_basedir->Value;
63 if($mysql_basedir == '/') { $mysql_basedir = '/usr/'; }
64 $status_count = 0;
65 $stats_function_disabled = 0;
66 ?>
67 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
68 <!-- Checking Backup Status -->
69 <div class="wrap">
70 <h2>Checking Backup Status</h2>
71 <p>
72 Checking Backup Folder (<b><?php echo stripslashes($backup['path']); ?></b>) ...<br />
73 <?php
74 if(is_dir(stripslashes($backup['path']))) {
75 echo '<font color="green">Backup folder exists</font><br />';
76 $status_count++;
77 } else {
78 echo '<font color="red">Backup folder does NOT exist. Please create \'backup-db\' folder in \'wp-content\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.</font><br />';
79 }
80 if(is_writable(stripslashes($backup['path']))) {
81 echo '<font color="green">Backup folder is writable</font>';
82 $status_count++;
83 } else {
84 echo '<font color="red">Backup folder is NOT writable. Please CHMOD it to \'777\'.</font>';
85 }
86 ?>
87 </p>
88 <p>
89 <?php
90 if(file_exists($mysql_basedir.'bin/'.stripslashes($backup['mysqldumppath']))) {
91 echo 'Checking MYSQL Dump Path (<b>'.$mysql_basedir.'bin/'.stripslashes($backup['mysqldumppath']).'</b>) ...<br />';
92 echo '<font color="green">MYSQL dump path exists.</font>';
93 $status_count++;
94 } else if(file_exists(stripslashes($backup['mysqldumppath']))) {
95 echo 'Checking MYSQL Dump Path (<b>'.stripslashes($backup['mysqldumppath']).'</b>) ...<br />';
96 echo '<font color="green">MYSQL dump path exists.</font>';
97 $status_count++;
98 } else {
99 echo 'Checking MYSQL Dump Path ...<br />';
100 echo '<font color="red">MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.</font>';
101 }
102 ?>
103 </p>
104 <p>
105 <?php
106 if(file_exists($mysql_basedir.'bin/'.stripslashes($backup['mysqlpath']))) {
107 echo 'Checking MYSQL Path (<b>'.$mysql_basedir.'bin/'.stripslashes($backup['mysqlpath']).'</b>) ...<br />';
108 echo '<font color="green">MYSQL path exists.</font>';
109 $status_count++;
110 } else if(file_exists(stripslashes($backup['mysqlpath']))) {
111 echo 'Checking MYSQL Path (<b>'.stripslashes($backup['mysqlpath']).'</b>) ...<br />';
112 echo '<font color="green">MYSQL path exists.</font>';
113 $status_count++;
114 } else {
115 echo 'Checking MYSQL Path ...<br />';
116 echo '<font color="red">MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.</font>';
117 }
118 ?>
119 </p>
120 <p>
121 Checking PHP Functions (<b>passthru()</b>, <b>system()</b> and <b>exec()</b>) ...<br />
122 <?php
123 if(function_exists('passthru')) {
124 echo '<font color="green">passthru() enabled.</font><br />';
125 $status_count++;
126 } else {
127 echo '<font color="red">passthru() disabled.</font><br />';
128 $stats_function_disabled++;
129 }
130 if(function_exists('system')) {
131 echo '<font color="green">system() enabled.</font><br />';
132 } else {
133 echo '<font color="red">system() disabled.</font><br />';
134 $stats_function_disabled++;
135 }
136 if(function_exists('exec')) {
137 echo '<font color="green">exec() enabled.</font>';
138 } else {
139 echo '<font color="red">exec() disabled.</font>';
140 $stats_function_disabled++;
141 }
142 ?>
143 </p>
144 <p>
145 <?php
146 if($status_count == 5) {
147 echo '<b><font color="green">Excellent. You Are Good To Go.</font></b>';
148 } else if($stats_function_disabled == 3) {
149 echo '<b><font color="red">I\'m sorry, your server administrator has disabled passthru(), system() and exec(), thus you cannot use this backup script. You may consider using the default WordPress database backup script instead.</font></b>';
150 } else {
151 echo '<b><font color="red">Please Rectify The Error Highlighted In Red Before Proceeding On.</font></b>';
152 }
153 ?>
154 </p>
155 <p><i>Note: The checking of backup status is still undergoing testing, if you get a 'Good To Go' status but can't perform the backup or you get some errors but still can perform the backup, please drop me an <a href="mailto:gamerz84@hotmail.com?Subject=WP-DBManager: Checking Of Backup Status">email</a>.</i></p>
156 </div>
157 <!-- Backup Database -->
158 <div class="wrap">
159 <h2>Backup Database</h2>
160 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
161 <table width="100%" cellspacing="3" cellpadding="3" border="0">
162 <tr style='background-color: #eee'>
163 <th align="left" scope="row">Database Name:</th>
164 <td><?php echo DB_NAME; ?></td>
165 </tr>
166 <tr style='background-color: none'>
167 <th align="left" scope="row">Database Backup To:</th>
168 <td><?php echo stripslashes($backup['path']); ?></td>
169 </tr>
170 <tr style='background-color: #eee'>
171 <th align="left" scope="row">Database Backup Date:</th>
172 <td><?php echo gmdate('l, jS F Y @ H:i', $backup['date']); ?></td>
173 </tr>
174 <tr style='background-color: none'>
175 <th align="left" scope="row">Database Backup File Name:</th>
176 <td><?php echo $backup['filename']; ?></td>
177 </tr>
178 <tr style='background-color: #eee'>
179 <th align="left" scope="row">Database Backup Type:</th>
180 <td>Full (Structure and Data)</td>
181 </tr>
182 <tr style='background-color: none'>
183 <th align="left" scope="row">MYSQL Dump Location:</th>
184 <td><?php echo stripslashes($backup['mysqldumppath']); ?></td>
185 </tr>
186 <tr style='background-color: #eee'>
187 <th align="left" scope="row">GZIP Database Backup File?</th>
188 <td><input type="radio" name="gzip" value="1" />Yes&nbsp;&nbsp;<input type="radio" name="gzip" value="0" checked="checked" />No</td>
189 </tr>
190 <tr>
191 <td colspan="2" align="center"><input type="submit" name="do" value="Backup" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
192 </tr>
193 </table>
194 </form>
195 </div>