def restore( snapshot_path, restore_dir, pubkeys, num_required ):
    
    global value_hashes

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG")
    assert config_path

    os.makedirs(restore_dir)
    shutil.copy(config_path, os.path.join(restore_dir, os.path.basename(config_path)))

    rc = blockstack.fast_sync_import( restore_dir, "file://{}".format(snapshot_path), public_keys=pubkeys, num_required=num_required )
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    # database must be identical 
    db_filenames = ['blockstack-server.db', 'blockstack-server.snapshots', 'blockstack-server.lastblock']
    src_paths = [os.path.join(virtualchain.get_working_dir(), fn) for fn in db_filenames]
    backup_paths = [os.path.join(restore_dir, fn) for fn in db_filenames]

    for src_path, backup_path in zip(src_paths, backup_paths):
        rc = os.system("cmp '{}' '{}'".format(src_path, backup_path))
        if rc != 0:
            print '{} disagress with {}'.format(src_path, backup_path)
            return False
    
    # all zone files must be present
    for vh in value_hashes:
        zfdata = blockstack.get_cached_zonefile_data(vh, zonefile_dir=os.path.join(restore_dir, 'zonefiles'))
        if zfdata is None:
            print 'Missing {} in {}'.format(vh, os.path.join(restore_dir, 'zonefiles'))
            return False

    shutil.rmtree(restore_dir)
    return True
def restore(working_dir, snapshot_path, restore_dir, pubkeys, num_required):

    global value_hashes

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG")
    assert config_path

    if os.path.exists(restore_dir):
        shutil.rmtree(restore_dir)

    os.makedirs(restore_dir)
    shutil.copy(config_path,
                os.path.join(restore_dir, os.path.basename(config_path)))

    rc = blockstack.fast_sync_import(restore_dir,
                                     "file://{}".format(snapshot_path),
                                     public_keys=pubkeys,
                                     num_required=num_required)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    # database must be identical
    db_filenames = [
        'blockstack-server.db', 'blockstack-server.snapshots', 'atlas.db',
        'subdomains.db'
    ]
    src_paths = [os.path.join(working_dir, fn) for fn in db_filenames]
    backup_paths = [os.path.join(restore_dir, fn) for fn in db_filenames]

    for src_path, backup_path in zip(src_paths, backup_paths):
        rc = os.system(
            'echo ".dump" | sqlite3 "{}" > "{}/first.dump"; echo ".dump" | sqlite3 "{}" > "{}/second.dump"; cmp "{}/first.dump" "{}/second.dump"'
            .format(src_path, restore_dir, backup_path, restore_dir,
                    restore_dir, restore_dir))

        if rc != 0:
            print '{} disagress with {}'.format(src_path, backup_path)
            return False

    # all zone files must be present
    for vh in value_hashes:
        zfdata = blockstack.get_atlas_zonefile_data(
            vh, os.path.join(restore_dir, 'zonefiles'))
        if zfdata is None:
            print 'Missing {} in {}'.format(
                vh, os.path.join(restore_dir, 'zonefiles'))
            return False

    # all import keychains must be present
    for ns in namespace_ids:
        import_keychain_path = blockstack.lib.namedb.BlockstackDB.get_import_keychain_path(
            restore_dir, ns)
        if not os.path.exists(import_keychain_path):
            print 'Missing import keychain {}'.format(import_keychain_path)
            return False

    return True
Пример #3
0
def restore(snapshot_path, restore_dir, pubkeys, num_required):

    global value_hashes

    config_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG")
    assert config_path

    os.makedirs(restore_dir)
    shutil.copy(config_path,
                os.path.join(restore_dir, os.path.basename(config_path)))

    rc = blockstack.fast_sync_import(restore_dir,
                                     "file://{}".format(snapshot_path),
                                     public_keys=pubkeys,
                                     num_required=num_required)
    if not rc:
        print "failed to restore snapshot {}".format(snapshot_path)
        return False

    # database must be identical
    db_filenames = [
        'blockstack-server.db', 'blockstack-server.snapshots',
        'blockstack-server.lastblock'
    ]
    src_paths = [
        os.path.join(virtualchain.get_working_dir(), fn) for fn in db_filenames
    ]
    backup_paths = [os.path.join(restore_dir, fn) for fn in db_filenames]

    for src_path, backup_path in zip(src_paths, backup_paths):
        rc = os.system("cmp '{}' '{}'".format(src_path, backup_path))
        if rc != 0:
            print '{} disagress with {}'.format(src_path, backup_path)
            return False

    # all zone files must be present
    for vh in value_hashes:
        zfdata = blockstack.get_cached_zonefile_data(vh,
                                                     zonefile_dir=os.path.join(
                                                         restore_dir,
                                                         'zonefiles'))
        if zfdata is None:
            print 'Missing {} in {}'.format(
                vh, os.path.join(restore_dir, 'zonefiles'))
            return False

    shutil.rmtree(restore_dir)
    return True