-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup_migrate.install
497 lines (454 loc) · 16.2 KB
/
backup_migrate.install
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<?php
/**
* @file
* Install hooks for Backup and Migrate.
*/
/**
* Implementation of hook_requirements().
*/
function backup_migrate_requirements($phase) {
$requirements = array();
return $requirements;
}
/**
* Implementation of hook_schema().
*/
function backup_migrate_schema() {
$schema['backup_migrate_profiles'] = array(
'fields' => array(
'profile_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'name' => array(
'description' => t('The name of the profile.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
'filename' => array(
'description' => t('The base pattern (including unreplaced tokens) for the name of the backup file.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
'append_timestamp' => array(
'description' => t('Append a timestamp to the filename.'),
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0
),
'timestamp_format' => array(
'description' => t('The format of the timestamp.'),
'type' => 'varchar',
'length' => 14,
'not null' => TRUE
),
'filters' => array(
'description' => t('The filter settings for the profile.'),
'type' => 'text',
'not null' => TRUE,
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'primary key' => array('profile_id'),
);
$schema['backup_migrate_destinations'] = array(
'fields' => array(
'destination_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'name' => array(
'description' => t('The name of the profile.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
'type' => array(
'description' => t('The type of the destination.'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE
),
'location' => array(
'description' => t('The the location string of the destination.'),
'type' => 'text',
'not null' => TRUE
),
'settings' => array(
'description' => t('Other settings for the destination.'),
'type' => 'text',
'not null' => TRUE,
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'primary key' => array('destination_id'),
);
$schema['backup_migrate_schedules'] = array(
'fields' => array(
'schedule_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'name' => array(
'description' => t('The name of the profile.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
'source_id' => array(
'description' => t('The {backup_migrate_destination}.destination_id of the source to backup from.'),
'type' => 'varchar',
'length' => 255,
'default' => 'db',
'not null' => TRUE
),
'destination_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The {backup_migrate_destination}.destination_id of the destination to back up to.'),
),
'profile_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'keep' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('The number of backups to keep.'),
),
'period' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('The number of seconds between backups.'),
),
'enabled' => array(
'description' => t('Whether the schedule is enabled.'),
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0
),
'cron' => array(
'description' => t('Whether the schedule should be run during cron.'),
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0
),
),
'primary key' => array('schedule_id'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function backup_migrate_install() {
drupal_install_schema('backup_migrate');
_backup_migrate_setup_database_defaults();
}
function _backup_migrate_setup_database_defaults() {
require_once './'. drupal_get_path('module', 'backup_migrate') .'/backup_migrate.module';
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/crud.inc';
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/files.inc';
if (variable_get("backup_migrate_file_name", NULL)) {
$settings = array(
'profile_id' => 'default',
'filename' => variable_get("backup_migrate_file_name", _backup_migrate_default_filename()),
'append_timestamp' => variable_get("backup_migrate_append_timestamp", FALSE) ? 1 : 0,
'timestamp_format' => variable_get("backup_migrate_timestamp_format", 'Y-m-d\TH-i-s'),
'filters' => array(
'compression' => variable_get("backup_migrate_compression", "none"),
'exclude_tables' => variable_get("backup_migrate_exclude_tables", array()),
'nodata_tables' => variable_get("backup_migrate_nodata_tables", array()),
),
'name' => t('Default Settings'),
);
$profile = backup_migrate_crud_create_item('profile', $settings);
$profile->save();
variable_set("backup_migrate_profile_id", 'default');
// Set up the default schedules.
if (variable_get("backup_migrate_schedule_backup_period", 0)) {
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/schedules.inc';
$schedule = array(
'name' => t('Default Schedule'),
'profile_id' => $profile->get_id(),
'enabled' => 1,
'destination_id' => 'scheduled',
'period' => array('number' => variable_get("backup_migrate_schedule_backup_period", 0), 'type' => 'hours'),
'keep' => variable_get("backup_migrate_schedule_backup_keep", 0),
);
$schedule = backup_migrate_crud_create_item('schedule', $schedule);
$schedule->save();
}
}
}
/**
* Remove variables on uninstall.
*/
function backup_migrate_uninstall() {
drupal_uninstall_schema('backup_migrate');
db_query("DELETE FROM {variable} WHERE name LIKE 'backup_migrate_%'");
cache_clear_all('variables', 'cache');
}
/**
* Update from 1.x to 2.x.
*/
function backup_migrate_update_2000() {
// Updating from version 1.x, need to populate the db.
drupal_install_schema('backup_migrate');
_backup_migrate_setup_database_defaults();
return array();
}
/**
* Adding filter field for dev release of 2009-01-28
*/
function backup_migrate_update_2001() {
$ret = array();
$schema = drupal_get_schema_unprocessed('backup_migrate', 'backup_migrate_profiles');
// Add the filters field to the db.
if (!db_column_exists('backup_migrate_profiles', 'filters')) {
db_add_field($ret, 'backup_migrate_profiles', 'filters', array('description' => t('The filter settings for the profile.'),'type' => 'text', 'not null' => TRUE));
}
// Add the source field
if (!db_column_exists('backup_migrate_profiles', 'source_id')) {
db_add_field($ret, 'backup_migrate_profiles', 'source_id', array('description' => t('The {backup_migrate_destination}.destination_id of the source to backup from.'), 'type' => 'varchar', 'length' => 255, 'default' => 'db', 'not null' => TRUE));
}
// Remove the compression field.
if (db_column_exists('backup_migrate_profiles', 'compression')) {
db_drop_field($ret, 'backup_migrate_profiles', 'compression');
}
return $ret;
}
/**
* Clearing the cache because there was a menu structure change in the dev of 2009-05-31
*/
function backup_migrate_update_2002() {
// Cache should clear automatically. Nothing to do here.
return array();
}
/**
* Allowing non-int profile ids in schedules 2009-05-31
*/
function backup_migrate_update_2003() {
$ret = array();
$spec = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
);
db_change_field($ret, 'backup_migrate_schedules', 'profile_id', 'profile_id', $spec);
return $ret;
}
/**
* Allowing non-int profile ids 2009-07-01
*/
function backup_migrate_update_2004() {
$ret = array();
$spec = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
);
$spec['description'] = t('The primary identifier for a destination.');
db_change_field($ret, 'backup_migrate_destinations', 'destination_id', 'destination_id', $spec);
$spec['description'] = t('The primary identifier for a profile.');
db_change_field($ret, 'backup_migrate_profiles', 'profile_id', 'profile_id', $spec);
$spec['description'] = t('The primary identifier for a schedule.');
db_change_field($ret, 'backup_migrate_schedules', 'schedule_id', 'schedule_id', $spec);
// Drop the user/pass fields as they weren't being used.
if (db_column_exists('backup_migrate_destinations', 'username')) {
db_drop_field($ret, 'backup_migrate_destinations', 'username');
}
if (db_column_exists('backup_migrate_destinations', 'password')) {
db_drop_field($ret, 'backup_migrate_destinations', 'password');
}
return $ret;
}
/**
* Change the default database id to something friendlier 2009-08-08
*/
function backup_migrate_update_2005() {
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/crud.inc';
require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';
$ret = array();
// Change the destination ids of the defined database sources mostly to make using them with drush friendlier.
// Change the db_url:default id to simply 'db'
$ret[] = update_sql("UPDATE {backup_migrate_profiles} SET source_id = 'db' WHERE source_id = 'db_url:default'");
$ret[] = update_sql("UPDATE {backup_migrate_schedules} SET destination_id = 'db' WHERE destination_id = 'db_url:default'");
// Change the defined db keys from db_url:key to db:key.
$ret[] = update_sql("UPDATE {backup_migrate_profiles} SET source_id = REPLACE(source_id, 'db_url:', 'db:')");
$ret[] = update_sql("UPDATE {backup_migrate_schedules} SET destination_id = REPLACE(destination_id, 'db_url:', 'db:')");
// Add the source field to the schedule
if (!db_column_exists('backup_migrate_schedules', 'source_id')) {
db_add_field($ret, 'backup_migrate_schedules', 'source_id', array('description' => t('The db source to backup from.'), 'type' => 'varchar', 'length' => 255, 'default' => 'db', 'not null' => TRUE));
}
// Copy source data from profiles to schedules.
$result = db_query('SELECT p.source_id, s.schedule_id FROM {backup_migrate_schedules} s LEFT JOIN {backup_migrate_profiles} p ON s.profile_id = p.profile_id');
while ($schedule = db_fetch_array($result)) {
if (!$schedule['source_id']) {
$schedule['source_id'] = 'db';
}
$ret[] = update_sql("UPDATE {backup_migrate_schedules} SET source_id = '". $schedule['source_id'] ."' WHERE schedule_id = '". $schedule['profile_id'] ."'");
}
if (db_column_exists('backup_migrate_profiles', 'source_id')) {
db_drop_field($ret, 'backup_migrate_profiles', 'source_id');
}
// Copy the no-data and exclude tables settings into the 'filter' field.
$result = db_query('SELECT * FROM {backup_migrate_profiles}');
while ($item = db_fetch_array($result)) {
if (isset($item['nodata_tables']) && isset($item['exclude_tables'])) {
$profile = backup_migrate_get_profile($item['profile_id']);
$profile->filters['nodata_tables'] = unserialize($item['nodata_tables']);
$profile->filters['exclude_tables'] = unserialize($item['exclude_tables']);
$profile->save();
}
}
if (db_column_exists('backup_migrate_profiles', 'nodata_tables')) {
db_drop_field($ret, 'backup_migrate_profiles', 'nodata_tables');
}
if (db_column_exists('backup_migrate_profiles', 'exclude_tables')) {
db_drop_field($ret, 'backup_migrate_profiles', 'exclude_tables');
}
return $ret;
}
/**
* Change the filename field to support 255 characters.
*/
function backup_migrate_update_2006() {
$ret = array();
db_change_field($ret, 'backup_migrate_profiles', 'filename', 'filename', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
return $ret;
}
/**
* Update the schedule last run times to use variables instead of saving with the schedule.
*/
function backup_migrate_update_6200() {
$ret = array();
$result = db_query('SELECT * FROM {backup_migrate_schedules}', array());
while ($item = db_fetch_array($result)) {
if (isset($item['last_run'])) {
variable_set('backup_migrate_schedule_last_run_' . $item['schedule_id'], $item['last_run']);
}
}
if (db_column_exists('backup_migrate_schedules', 'last_run')) {
db_drop_field($ret, 'backup_migrate_schedules', 'last_run');
}
return $ret;
}
/**
* Disable the NodeSquirrel module if it's installed.
*/
function backup_migrate_update_6201() {
if (module_exists('nodesquirrel')) {
module_disable(array('nodesquirrel'));
drupal_set_message(t("The NodeSquirrel module was disabled. NodeSquirrel support is now built into Backup and Migrate."));
}
return array();
}
/**
* Increase the length of all ids to 255.
*/
function backup_migrate_update_6205() {
$schema['backup_migrate_profiles'] = array(
'fields' => array(
'profile_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'filename' => array(
'description' => t('The base pattern (including unreplaced tokens) for the name of the backup file.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
),
);
$schema['backup_migrate_destinations'] = array(
'fields' => array(
'destination_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
),
);
$schema['backup_migrate_schedules'] = array(
'fields' => array(
'schedule_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
'source_id' => array(
'description' => t('The {backup_migrate_destination}.destination_id of the source to backup from.'),
'type' => 'varchar',
'length' => 255,
'default' => 'db',
'not null' => TRUE
),
'destination_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The {backup_migrate_destination}.destination_id of the destination to back up to.'),
),
'profile_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => t('The primary identifier for a profile.'),
),
),
);
$fields = array(
'backup_migrate_profiles' => array('profile_id'),
'backup_migrate_destinations' => array('destination_id'),
'backup_migrate_schedules' => array('schedule_id', 'source_id', 'destination_id', 'profile_id'),
);
$ret = array();
// Update the length of each of the ids
foreach ($schema as $table => $ids) {
foreach ($ids['fields'] as $field => $spec) {
db_change_field($ret, $table, $field, $field, $spec);
}
}
return $ret;
}