def generate_restore_items(cls, project_id, dataset_id, target_project_id, target_dataset_id, max_partition_days): if max_partition_days: table_entities = Table \ .get_tables_with_max_partition_days(project_id, dataset_id, max_partition_days) else: table_entities = Table.get_tables(project_id, dataset_id) for table_entity_sublist in paginated(1000, table_entities): restore_items = [] for table_entity, backup_entity in Table.get_last_backup_for_tables( table_entity_sublist): if backup_entity is not None: source_table_reference = \ RestoreTableReference.backup_table_reference( table_entity, backup_entity) target_table_reference = TableReference( target_project_id, target_dataset_id, table_entity.table_id, table_entity.partition_id ) restore_item = RestoreItem.create(source_table_reference, target_table_reference) restore_items.append(restore_item) logging.info("Restore items generator yields %s restore items", len(restore_items)) yield restore_items
def __get_tables(self, project_id, dataset_id, max_partition_days): if max_partition_days is None: return Table.get_tables(project_id, dataset_id, page_size=20) else: return Table.get_tables_with_max_partition_days(project_id, dataset_id, max_partition_days, page_size=20)