source_blob_service = PageBlobService(args.sourceaccount, args.sourcekey)
backup_blob_service = PageBlobService(args.backupaccount, args.backupkey)

# Find page differences between snapshots and update backup blob with changes

try:
    ranges = source_blob_service.get_page_ranges_diff(args.sourcecontainer, args.sourceblob, args.snapshotprevious, args.snapshotcurrent)
    for range in ranges:
        if range.is_cleared == True:
            print('clearing page range: ({}, {}) '.format(range.start, range.end))
            backup_blob_service.clear_page(args.backupcontainer, args.backupblob, range.start, range.end)
        else:
            byte_offset = 0
            last_range = False
            while True:
                start_range = range.start + byte_offset
                end_range = start_range + max_range - 1
                if end_range >= range.end:
                    end_range = range.end
                    last_range = True
                print('updating page range: ({}, {}, {} bytes) '.format(start_range, end_range, end_range - start_range + 1))
                page = source_blob_service.get_blob_to_bytes(args.sourcecontainer, args.sourceblob, args.snapshotcurrent, start_range, end_range)
                backup_blob_service.update_page(args.backupcontainer, args.backupblob, page.content, start_range, end_range) 
                if last_range:
                    break
                byte_offset = byte_offset + max_range
except:
    sys.exit(1)
else:
    sys.exit(0)
Пример #2
0
    # d = scaled.tobytes()

    entity = table_service.get_entity(table_name='devices',
                                      partition_key='engine',
                                      row_key='1')

    signal, last_speed = generate(t,
                                  wk,
                                  Ak,
                                  last_speed=last_speed,
                                  target_speed=entity.speed)

    signal.resize(16 * 512)
    signal[fs] = last_speed

    d = signal.tobytes()

    page_start = i * 32 * 512
    page_end = page_start + 32 * 512 - 1

    r = az_blob_service.set_sequence_number(CONTAINER_NAME,
                                            "buffer",
                                            sequence_number_action="increment")
    az_blob_service.update_page(CONTAINER_NAME, "buffer", d, page_start,
                                page_end)

    i = (i + 1) % 10
    t += 1
    print(time())
    sleep(max(0, start + t - time()))
    for range in ranges:
        if range.is_cleared == True:
            print('clearing page range: ({}, {}) '.format(
                range.start, range.end))
            backup_blob_service.clear_page(args.backupcontainer,
                                           args.backupblob, range.start,
                                           range.end)
        else:
            byte_offset = 0
            last_range = False
            while True:
                start_range = range.start + byte_offset
                end_range = start_range + max_range - 1
                if end_range >= range.end:
                    end_range = range.end
                    last_range = True
                print('updating page range: ({}, {}, {} bytes) '.format(
                    start_range, end_range, end_range - start_range + 1))
                page = source_blob_service.get_blob_to_bytes(
                    args.sourcecontainer, args.sourceblob,
                    args.snapshotcurrent, start_range, end_range)
                backup_blob_service.update_page(args.backupcontainer,
                                                args.backupblob, page.content,
                                                start_range, end_range)
                if last_range:
                    break
                byte_offset = byte_offset + max_range
except:
    sys.exit(1)
else:
    sys.exit(0)