@@ -50,8 +50,8 @@ function setDatabaseToBackup($name)
50
50
51
51
function listAvailableObjectsToBackup ($ kind =false )
52
52
{
53
- /*if ($kind==self::KIND_TABLES) {
54
- return array('_as_linkmanager_links ');
53
+ /*if ($kind==self::KIND_TABLES || $kind==self::KIND_DATA ) {
54
+ return array('video ');
55
55
}*/
56
56
57
57
if ($ kind ===false ) {
@@ -90,24 +90,24 @@ protected function _prepareBackup()
90
90
91
91
}
92
92
93
- function doBackup ($ storeCallback )
93
+ function doBackup ($ store )
94
94
{
95
95
// make sure we already prepared backup
96
96
$ this ->_prepareBackup ();
97
97
98
98
foreach ($ this ->_kindsToBackup as $ kind ) {
99
99
$ funcName = "_backup " .ucfirst ($ kind );
100
100
if (method_exists ($ this , $ funcName )) {
101
- $ this ->$ funcName ($ storeCallback );
101
+ $ this ->$ funcName ($ store );
102
102
} else {
103
103
echo "don't know of to backup objects of type ' $ kind'. \n" ;
104
104
}
105
105
}
106
106
}
107
- function _backupRefs ($ storeCallback ) {}
108
- function _backupIndexes ($ storeCallback ) {}
107
+ function _backupRefs ($ store ) {}
108
+ function _backupIndexes ($ store ) {}
109
109
110
- function _backupTables ($ storeCallback )
110
+ function _backupTables ($ store )
111
111
{
112
112
foreach ($ this ->listAvailableObjectsToBackup (self ::KIND_TABLES ) as $ def ) {
113
113
// info SHOW TABLE STATUS LIKE 'TABLES';
@@ -166,37 +166,38 @@ function _backupTables($storeCallback)
166
166
167
167
// store the table
168
168
$ tbl = implode (PHP_EOL , $ tbl );
169
- call_user_func ($ storeCallback , self ::KIND_TABLES , $ def , $ tbl .'; ' );
169
+
170
+ $ store ->storeDbObject (self ::KIND_TABLES , $ def , $ tbl .'; ' );
170
171
171
172
// store tables indexes
172
173
if (count ($ idx )) {
173
174
array_unshift ($ idx , "ALTER TABLE ` $ def` " );
174
175
$ idx [count ($ idx )-1 ] = rtrim ($ idx [count ($ idx )-1 ], ', ' );
175
176
$ idx = implode (PHP_EOL , $ idx );
176
- call_user_func ( $ storeCallback , self ::KIND_INDEXES , $ def , $ idx .'; ' );
177
+ $ store -> storeDbObject ( self ::KIND_INDEXES , $ def , $ idx .'; ' );
177
178
}
178
179
179
180
// store table constraints
180
181
if (count ($ refs )) {
181
182
array_unshift ($ refs , "ALTER TABLE ` $ def` " );
182
183
$ refs = implode (PHP_EOL , $ refs );
183
- call_user_func ( $ storeCallback , self ::KIND_REFS , $ def , $ refs .'; ' );
184
+ $ store -> storeDbObject ( self ::KIND_REFS , $ def , $ refs .'; ' );
184
185
}
185
186
}
186
187
}
187
188
}
188
189
189
- function _backupData ($ storeCallback )
190
+ function _backupData ($ store )
190
191
{
191
192
// TODO detect if server is localhost
192
193
if (false ) {
193
- $ this ->_backupDataFromLocal ($ storeCallback );
194
+ $ this ->_backupDataFromLocal ($ store );
194
195
} else {
195
- $ this ->_backupDataFromRemote ($ storeCallback );
196
+ $ this ->_backupDataFromRemote ($ store );
196
197
}
197
198
}
198
199
199
- function _backupDataFromLocal ($ storeCallback )
200
+ function _backupDataFromLocal ($ store )
200
201
{
201
202
// TODO not implemented
202
203
/**
@@ -210,10 +211,65 @@ function _backupDataFromLocal($storeCallback)
210
211
}
211
212
}
212
213
213
- function _backupDataFromRemote ($ storeCallback )
214
+ function _backupDataFromRemote ($ store )
214
215
{
215
216
foreach ($ this ->listAvailableObjectsToBackup (self ::KIND_DATA ) as $ def ) {
217
+ $ fn = $ store ->storeFilenameFor (self ::KIND_DATA , $ def );
218
+ $ f = fopen ($ fn , "w " );
219
+ $ this ->_tableDataToCsv ($ def , $ f );
220
+ fclose ($ f );
221
+ }
222
+ }
216
223
224
+ protected function _tableDataToCsv ($ tableName , $ f )
225
+ {
226
+ // TODO it may be better if Storage_Mysql whould hangle storing of array data
227
+ $ q = $ this ->_db ->query ("SELECT * FROM ` {$ this ->_dbName }`.` $ tableName` " );
228
+ //$q = $this->_db->query("SELECT * FROM `a`.`a_export`");
229
+ while (false !==($ data =$ q ->fetch (PDO ::FETCH_NUM ))) {
230
+ // we have to convert null fields to \N
231
+ foreach ($ data as &$ c ) {
232
+ if (is_null ($ c )) {
233
+ $ c = "\N " ;
234
+ } else {
235
+ $ c = strtr ($ c , array (
236
+ "\\" => "\\\\" ,
237
+ "\t" => "\\\t" ,
238
+ "\n" => "\\\n" ,
239
+ "\r" => "\\\r" ,
240
+ ));
241
+ }
242
+ }
243
+
244
+ // store data in tab delimited format
245
+ //fputcsv($f, $data, "\t", ' ');
246
+ fwrite ($ f , implode ("\t" , $ data ).chr (13 ).chr (10 ));
217
247
}
218
248
}
249
+
219
250
}
251
+
252
+ SELECT * INTO OUTFILE '/tmp/a_export ' FROM a_export
253
+
254
+
255
+
256
+
257
+
258
+ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ ;
259
+ /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */ ;
260
+ /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */ ;
261
+ /*!40101 SET NAMES utf8 */ ;
262
+ /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */ ;
263
+ /*!40103 SET TIME_ZONE='+00:00' */ ;
264
+ /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */ ;
265
+ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */ ;
266
+ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
267
+ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */ ;
268
+ TRUNCATE TABLE cms_page;
269
+ LOAD DATA LOCAL INFILE '/home/k2s/Backups/xtbackupMysql/data/cms_page ' INTO TABLE cms_page CHARACTER SET UTF8 ;
270
+ select count(*) from cms_page;
271
+
272
+
273
+
274
+ DROP DATABASE a;
275
+ CREATE DATABASE a;
0 commit comments