Skip to content

Commit 4af3ee0

Browse files
author
Yehonal
committed
added project files
1 parent 18da34e commit 4af3ee0

File tree

9 files changed

+1895
-0
lines changed

9 files changed

+1895
-0
lines changed

bigdump.php

Lines changed: 1108 additions & 0 deletions
Large diffs are not rendered by default.

configuration.php.dist

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
//[TODO] implements as class
3+
// basic configuration entries
4+
$secret = 'foo'; // a password to prevent unauthorized access to the script
5+
$from = '[email protected]'; // email address for the "from" header
6+
$to = '[email protected]'; // address to which emails will be sent
7+
$bundle_name = 'backups'; // date/time will be appended to the bundle name
8+
$email = 0; // 0 = don't send the completion email (error emails will still be sent)
9+
// 1 = send email notice upon successful completion,
10+
$debug = 1; // 0 = don't print to browser, use this when executing from cron!
11+
// 1 = print debug information to browser
12+
$command = 'mysqldump'; // The mysqldump program name. Should work as is. If you get an empty
13+
// backup file try entering the full path to the dump program. e.g.
14+
// /user/bin/mysqldump
15+
16+
// the first database to be backed up - referred to in the user guide as"dbid=0"
17+
$cfg[0]['dbhost'] = ""; // your mySQL server name
18+
$cfg[0]['dbuser'] = ""; // your mySQL user name
19+
$cfg[0]['dbpass'] = ""; // your mySQL password
20+
$cfg[0]['dbname'] = ""; // database name
21+
$cfg[0]['dbprefix'] = ""; // empty = backup all tables in the database
22+
// prefix string = backup only table names beginning with the string
23+
$cfg[0]['optimize'] = '1'; // 1 = optimize tables, 0 = don't optimize them
24+
$cfg[0]['extended_inserts'] = '1'; // 1 = one INSERT per table (smaller file), 0 = one INSERT per row
25+
$cfg[0]['options'] = ''; // add any additional mysqldump optons if you know what you are doing
26+
27+
// uncomment and edit the below entries to add another database
28+
// you can add any number of additional databases, each will be put in a separate output file
29+
// each will be one ID number greater...$cfg[1] dbid=1, $cfg[2] dbid=2, etc.
30+
31+
/*
32+
// 2nd database
33+
$cfg[1]['dbhost'] = '';
34+
$cfg[1]['dbuser'] = '';
35+
$cfg[1]['dbpass'] = '';
36+
$cfg[1]['dbname'] = '';
37+
$cfg[1]['dbprefix'] = '';
38+
$cfg[1]['optimize'] = '';
39+
$cfg[1]['extended_inserts'] = '';
40+
$cfg[1]['options'] = '';
41+
*/
42+
?>

configuration.sh.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DS_URL=""
2+
3+
# FTP
4+
FTP_USER=user
5+
FTP_PASSWD=password
6+
FTP_HOST=$SITE_HOST
7+
FTP_PATH='trunk/hw2'
8+
9+
FILENAME='my_db.sql'
10+
REMOTEFILE=$FTP_PATH'/'$DIR$FILENAME'.gz'
11+
LOCALFILE=$1'/'$DIR$FILENAME'.gz'
12+
13+
RDUMP_OPT=""
14+
15+

dbsync.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
defined("DBSYNC_EXEC") or define("DBSYNC_EXEC",1);
3+
defined("DBSYNC_PATH") or define("DBSYNC_PATH", dirname(__FILE__).DIRECTORY_SEPARATOR);
4+
5+
class dbSync {
6+
/**
7+
* call init to run dbsync
8+
*/
9+
public static function init($dbpath) {
10+
global $hw2ds_dbpath;
11+
$hw2ds_dbpath=$dbpath;
12+
if ($_GET["method"]=="import") {
13+
echo "importing..";
14+
require "import.php";
15+
} else {
16+
echo "exporting..";
17+
require "export.php";
18+
}
19+
}
20+
}
21+
22+
?>

export.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php defined("DBSYNC_EXEC") or die("dbsync not loaded correctly");
2+
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3+
Backup mySql tables
4+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5+
Copyright 2006 by Richard Williamson (aka OldGuy).
6+
Website: http://www.scripts.oldguy.us - [email protected]
7+
Support: http://www.scripts.oldguy.us/forums/
8+
Licensed under the terms of the GNU General Public License, June 1991.
9+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10+
*/
11+
12+
include 'functions.php';
13+
14+
// ---- end of configuration settings array -----
15+
// Don't change anything after this line unless you know what you are doing
16+
17+
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18+
Dump a database to a file and send email containing download link
19+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20+
mysqldump.php, version 1.3, Feb 2009
21+
By Richard Williamson (aka OldGuy).
22+
Website: http://www.scripts.oldguy.us/mybackup
23+
24+
25+
Licensed under the terms of the GNU General Public License, June 1991.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34+
*/
35+
36+
// are we downloading a file?
37+
/*if ($filename) {
38+
// secret code is not required, the file name is dynamically generated and thus relatively secure
39+
downloadFile($filename);
40+
exit();
41+
}*/
42+
43+
if ($code != $secret) {
44+
$msg = "Invalid code ".$secret." in the query string: ?{$_SERVER['QUERY_STRING']}";
45+
if ($debug) print "$msg<br />";
46+
sendLog(1, $msg . EOL);
47+
exit();
48+
}
49+
50+
// are we downloading a bundle?
51+
if ($bundle) {
52+
sendBundle();
53+
exit();
54+
}
55+
56+
if (!is_numeric($dbid) || $dbid > count($cfg) || $dbid < 0) {
57+
$msg = "Invalid or missing dbid argument in the query string: ?{$_SERVER['QUERY_STRING']}";
58+
if ($debug) print "$msg<br />";
59+
sendLog(1, $msg . EOL);
60+
}
61+
62+
// Mmake sure we can write the dump file
63+
$time = date('Ymd_His');
64+
65+
$dumpfile = $dir . $filename /* $time . */;
66+
if ($handle = @fopen($dumpfile, 'w')) {
67+
fclose($handle);
68+
} else {
69+
$msg = "Unable to open '$dumpfile' for writing.". EOL;
70+
if ($debug) print "$msg<bmy_hw2_20111111_034837_old.sql.gzr />";
71+
sendLog(1, $msg . EOL);
72+
}
73+
74+
75+
// delete old backup files for the database
76+
deleteFiles();
77+
78+
// Open the database
79+
$dblink = @mysql_connect($dbhost, $dbuser, $dbpass);
80+
if (!$dblink) {
81+
$msg = "Unable to connect to mysql server using the host, user and password in \$cfg[$dbid]". EOL;
82+
if ($debug) print "$msg<br />";
83+
sendLog(1, $msg . EOL);
84+
}
85+
$result = @mysql_select_db($dbname);
86+
if (!$result) {
87+
$msg = "The database does not exist or the \$cfg[$dbid] user does not have permission to access it". EOL;
88+
if ($debug) print "$msg<br />";
89+
sendLog(1, $msg . EOL);
90+
}
91+
92+
// Get table names
93+
$rows = 0;
94+
$tables = array();
95+
$result = mysql_query("SHOW TABLES FROM $dbname ", $dblink);
96+
if (!$result) {
97+
$msg = "Error doing SHOW TABLES " . mysql_error() . EOL;
98+
if ($debug) print "$msg<br />";
99+
sendLog(1, $msg . EOL);
100+
}
101+
while (list($table_name) = mysql_fetch_row($result)) {
102+
if ($dbprefix) {
103+
if (preg_match("/^$dbprefix/", $table_name)) {
104+
$tables[$rows] = $table_name;
105+
$rows++;
106+
}
107+
} else {
108+
$tables[$rows] = $table_name;
109+
$rows++;
110+
}
111+
112+
}
113+
114+
// Optimize tables, build dump command tables variable
115+
$tables_list = '';
116+
$msg = '';
117+
for($i = 0; $i < $rows; $i++) {
118+
if ($dbprefix) $tables_list .= " {$tables[$i]}";
119+
if ($optimize) {
120+
$result = mysql_query("OPTIMIZE TABLE {$tables[$i]}", $dblink);
121+
if (!$result) $msg .= "Optimize query failed. mysql error = " . mysql_error() . EOL . EOL;
122+
}
123+
}
124+
125+
if ($msg) sendLog(0, $msg . EOL);
126+
if ($debug) print "$i tables were optimized<br />";
127+
128+
// dump the database
129+
//$options .= ($inserts) ? '' : ' --skip-extended-insert ';
130+
//$cmd = "$command $options --user=$dbuser --password=$dbpass $dbname $tables_list | gzip > $dumpfile";
131+
//$last_line = system($cmd, $result);
132+
133+
mysql_close($dblink);
134+
135+
backup_tables($dumpfile,$dbhost, $dbuser, $dbpass, $dbname);
136+
137+
if ($debug) print "<p>completed</p>";
138+
139+
if ($email) sendLog(1, "Download the dump file: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?filename=$dumpfile" . EOL);
140+
141+
?>

0 commit comments

Comments
 (0)