258
//-------------------------------
259
class StartBackupCleanUp : public CSRefObject {
265
StartBackupCleanUp(): CSRefObject(),
268
~StartBackupCleanUp()
271
backup->completeBackup();
275
void setCleanUp(MSBackup *bup)
223
288
void MSBackup::startBackup(MSDatabase *src_db)
225
290
CSSyncVector *repo_list;
226
291
bool compacting = false;
227
292
MSRepository *repo;
293
StartBackupCleanUp *cleanup;
231
bu_SourceDatabase = src_db;
232
repo_list = bu_SourceDatabase->getRepositoryList();
233
// Suspend the compactor before locking the list.
234
bu_Compactor = bu_SourceDatabase->getCompactorThread();
236
bu_Compactor->retain();
237
bu_Compactor->suspend();
240
// Build the list of repositories to be backed up.
243
new_(bu_BackupList, CSVector(repo_list->size()));
244
for (uint32_t i = 0; i<repo_list->size(); i++) {
245
if ((repo = (MSRepository *) repo_list->get(i))) {
246
if (!repo->isRemovingFP && !repo->mustBeDeleted) {
247
bu_BackupList->add(RETAIN(repo));
248
if (repo->initBackup() == REPO_COMPACTING)
251
if (!repo->myRepoHeadSize) {
252
/* The file has not yet been opened, so the
253
* garbage count will not be known!
255
MSRepoFile *repo_file;
258
//unlock_(myRepostoryList);
260
repo_file = repo->openRepoFile();
261
repo_file->release();
263
//lock_(myRepostoryList);
267
bu_size += repo->myRepoFileSize;
296
// Create a cleanup object to handle cleanup
297
// after a possible exception.
298
new_(cleanup, StartBackupCleanUp());
300
cleanup->setCleanUp(this);
302
bu_SourceDatabase = src_db;
303
repo_list = bu_SourceDatabase->getRepositoryList();
304
// Suspend the compactor before locking the list.
305
bu_Compactor = bu_SourceDatabase->getCompactorThread();
307
bu_Compactor->retain();
308
bu_Compactor->suspend();
311
// Build the list of repositories to be backed up.
314
new_(bu_BackupList, CSVector(repo_list->size()));
315
for (uint32_t i = 0; i<repo_list->size(); i++) {
316
if ((repo = (MSRepository *) repo_list->get(i))) {
317
if (!repo->isRemovingFP && !repo->mustBeDeleted) {
318
bu_BackupList->add(RETAIN(repo));
319
if (repo->initBackup() == REPO_COMPACTING)
322
if (!repo->myRepoHeadSize) {
323
/* The file has not yet been opened, so the
324
* garbage count will not be known!
326
MSRepoFile *repo_file;
329
//unlock_(myRepostoryList);
331
repo_file = repo->openRepoFile();
332
repo_file->release();
334
//lock_(myRepostoryList);
338
bu_size += repo->myRepoFileSize;
273
// Copy the table list to the backup database:
274
uint32_t next_tab = 0;
276
while ((tab = bu_SourceDatabase->getNextTable(&next_tab))) {
278
bu_Database->addTable(tab->myTableID, tab->myTableName->getCString(), 0, false);
283
// Copy over any physical PBMS system tables.
284
PBMSSystemTables::transferSystemTables(RETAIN(bu_Database), RETAIN(bu_SourceDatabase));
286
// Load the system tables into the backup database. This will
287
// initialize the database for cloud storage if required.
288
PBMSSystemTables::loadSystemTables(RETAIN(bu_Database));
290
// Set the cloud backup info.
291
bu_Database->myBlobCloud->cl_setBackupInfo(RETAIN(bu_info));
294
// Set the backup number in the pbms_variable tabe. (This is a hidden value.)
295
// This value is used in case a drag and drop restore was done. When a data base is
296
// first loaded this value is checked and if it is not zero then the backup record
297
// will be read and any used to recover any BLOBs.
300
snprintf(value, 20, "%"PRIu32"", bu_info->getBackupRefId());
301
MSVariableTable::setVariable(RETAIN(bu_Database), BACKUP_NUMBER_VAR, value);
303
// Once the repositories are locked the compactor can be restarted
304
// unless it is in the process of compacting a repository that is
306
if (bu_Compactor && !compacting) {
307
bu_Compactor->resume();
308
bu_Compactor->release();
312
// Suspend the transaction writer while the backup is running.
313
MSTransactionManager::suspend(true);
314
bu_TransactionManagerSuspended = true;
316
// Start the backup daemon thread.
317
bu_ID = bu_start_time = time(NULL);
344
// Copy the table list to the backup database:
345
uint32_t next_tab = 0;
347
while ((tab = bu_SourceDatabase->getNextTable(&next_tab))) {
349
bu_Database->addTable(tab->myTableID, tab->myTableName->getCString(), 0, false);
354
// Copy over any physical PBMS system tables.
355
PBMSSystemTables::transferSystemTables(RETAIN(bu_Database), RETAIN(bu_SourceDatabase));
357
// Load the system tables into the backup database. This will
358
// initialize the database for cloud storage if required.
359
PBMSSystemTables::loadSystemTables(RETAIN(bu_Database));
361
// Set the cloud backup info.
362
bu_Database->myBlobCloud->cl_setBackupInfo(RETAIN(bu_info));
365
// Set the backup number in the pbms_variable tabe. (This is a hidden value.)
366
// This value is used in case a drag and drop restore was done. When a data base is
367
// first loaded this value is checked and if it is not zero then the backup record
368
// will be read and any used to recover any BLOBs.
371
snprintf(value, 20, "%"PRIu32"", bu_info->getBackupRefId());
372
MSVariableTable::setVariable(RETAIN(bu_Database), BACKUP_NUMBER_VAR, value);
374
// Once the repositories are locked the compactor can be restarted
375
// unless it is in the process of compacting a repository that is
377
if (bu_Compactor && !compacting) {
378
bu_Compactor->resume();
379
bu_Compactor->release();
383
// Suspend the transaction writer while the backup is running.
384
MSTransactionManager::suspend(true);
385
bu_TransactionManagerSuspended = true;
387
// Start the backup daemon thread.
388
bu_ID = bu_start_time = time(NULL);
391
cleanup->cancelCleanUp();
330
397
void MSBackup::completeBackup()
380
447
bool MSBackup::doWork()
383
MSRepository *src_repo, *dst_repo;
384
MSRepoFile *src_file, *dst_file;
385
off64_t src_offset, prev_offset;
387
uint64_t blob_size, blob_data_size;
388
CSStringBuffer *head;
389
MSRepoPointersRec ptr;
390
uint32_t table_ref_count;
391
uint32_t blob_ref_count;
398
uint32_t src_repo_id;
400
uint8_t blob_storage_type;
403
char transferBuffer[MS_BACKUP_BUFFER_SIZE];
404
CloudKeyRec cloud_key;
408
bu_BackupRunning = true;
409
bu_State = BU_RUNNING;
415
myWaitTime = 5 * 1000; // Time in milli-seconds
452
MSRepository *src_repo, *dst_repo;
453
MSRepoFile *src_file, *dst_file;
454
off64_t src_offset, prev_offset;
456
uint64_t blob_size, blob_data_size;
457
CSStringBuffer *head;
458
MSRepoPointersRec ptr;
459
uint32_t table_ref_count;
460
uint32_t blob_ref_count;
467
uint32_t src_repo_id;
469
uint8_t blob_storage_type;
472
char transferBuffer[MS_BACKUP_BUFFER_SIZE];
473
CloudKeyRec cloud_key;
476
bu_BackupRunning = true;
477
bu_State = BU_RUNNING;
483
myWaitTime = 5 * 1000; // Time in milli-seconds
422
489
new_(head, CSStringBuffer(100));