static int recov_complete( void ) { int rc; lmgr_recov_stat_t stats; rc = ListMgr_RecovComplete( &lmgr, &stats ); if ( rc == DB_NOT_ALLOWED ) { printf("\nCannot complete recovery\n\n"); printf("Current status:\n"); print_recov_stats( FALSE, &stats ); return rc; } else if ( rc == DB_NOT_EXISTS ) { printf("\nERROR: There is no pending recovery.\n" ); return rc; } else if ( rc != DB_SUCCESS ) { printf("\nERROR %d finalizing recovery\n", rc ); return rc; } else { printf("\nRecovery successfully completed:\n"); print_recov_stats( FALSE, &stats ); return 0; } }
static int recov_status(void) { int rc; lmgr_recov_stat_t stats; rc = ListMgr_RecovStatus(&lmgr, &stats); if (rc) { if (rc == DB_NOT_EXISTS) fprintf(stderr, "ERROR: There is no pending recovery\n"); return rc; } printf("Current recovery status:\n"); print_recov_stats(false, &stats); printf("\n"); return 0; }
static int recov_reset(int force) { int rc; /* ask confirmation */ if ( !force ) { lmgr_recov_stat_t stats; char * buff = malloc(1024); size_t sz = 1024; rc = ListMgr_RecovStatus( &lmgr, &stats ); if (rc) { if ( rc == DB_NOT_EXISTS ) fprintf( stderr, "ERROR: There is no pending recovery\n" ); return rc; } printf( "\nWARNING: you are about to abort the current recovery.\n" ); printf( "All entries not yet recovered will be definitely lost!\n\n"); printf( "Current recovery status:\n"); print_recov_stats( FALSE, &stats ); printf("\n"); do { printf( "Do you really want to proceed [y/n]: " ); if ( getline( &buff, &sz, stdin ) > 0 ) { if ( !strcasecmp(buff, "y\n") || !strcasecmp(buff, "yes\n") ) break; else { printf("Aborted\n"); free(buff); return -ECANCELED; } } } while(1); free(buff); } return ListMgr_RecovReset( &lmgr ); }
static int recov_start(void) { lmgr_recov_stat_t stats; int rc; /* is there a filter to be applied? */ if (ost_list.count > 0 || since_time != 0) { lmgr_filter_t filter; filter_value_t fv; lmgr_simple_filter_init(&filter); /* ost filter? */ if (ost_list.count == 1) { printf("only recovering files striped on OST#%u\n", ost_list.values[0].val_uint); fv.value.val_uint = ost_list.values[0].val_uint; lmgr_simple_filter_add(&filter, ATTR_INDEX_stripe_items, EQUAL, fv, 0); } else if (ost_list.count > 1) { printf("only recovering files striped on OSTs[%s]\n", ost_range_str); fv.list = ost_list; lmgr_simple_filter_add(&filter, ATTR_INDEX_stripe_items, IN, fv, /* allow it to free ost_list->values: */ FILTER_FLAG_ALLOC_LIST); } /* update time filter */ if (since_time) { char date[128]; struct tm t; strftime(date, 128, "%Y/%m/%d %T", localtime_r(&since_time, &t)); printf("only recovering files updated after %s (timestamp: %lu)\n", date, since_time); fv.value.val_uint = since_time; lmgr_simple_filter_add(&filter, ATTR_INDEX_md_update, MORETHAN, fv, 0); } rc = ListMgr_RecovInit(&lmgr, &filter, &stats); } else rc = ListMgr_RecovInit(&lmgr, NULL, &stats); if (rc == 0) { printf("\nRecovery successfully initialized.\n\n"); printf("It should result in the following state:\n"); print_recov_stats(true, &stats); return 0; } else if (rc == DB_ALREADY_EXISTS) { printf("\nERROR: a recovery is already in progress, or a previous recovery\n" "was not completed properly (see --resume, --complete or --reset option).\n\n"); unsigned long long total = stats.status_count[RS_FILE_OK] + stats.status_count[RS_FILE_DELTA] + stats.status_count[RS_NON_FILE] + stats.status_count[RS_FILE_EMPTY] + stats.status_count[RS_NOBACKUP] + stats.status_count[RS_ERROR]; printf("The progress of this recovery is %Lu/%Lu entries\n", total, stats.total); print_recov_stats(false, &stats); return -EALREADY; } else { /* other error */ fprintf(stderr, "ERROR initializing recovery: db error %d\n", rc); return rc; } }