def restore_dst_cluster(dump_path, cluster_info, redis_time_out):

    from physical.models import Host
    for instance_info in cluster_info:
        sys_user = instance_info['sys_user']
        sys_pass = instance_info['sys_pass']
        remote_path = instance_info['remote_path']
        redis_pass = instance_info['redis_pass']
        redis_port = instance_info['redis_port']
        host = instance_info['host']

        click.echo("Restoring target database...")
        Host.run_script(address=host.address,
                        username=sys_user,
                        password=sys_pass,
                        script=host.commands.database(action='stop'))

    for instance_info in cluster_info:
        sys_user = instance_info['sys_user']
        sys_pass = instance_info['sys_pass']
        remote_path = instance_info['remote_path']
        redis_pass = instance_info['redis_pass']
        redis_port = instance_info['redis_port']
        host = instance_info['host']

        try:
            transport = paramiko.Transport((host, 22))
            transport.connect(username=sys_user, password=sys_pass)

            sftp = paramiko.SFTPClient.from_transport(transport)
            sftp.put(dump_path, remote_path)

            sftp.close()
            transport.close()
        except Exception, e:
            click.echo('ERROR while transporting dump file: {}'.format(e))
            return False

        Host.run_script(
            address=host.address,
            username=sys_user,
            password=sys_pass,
            script="sed -i 's/appendonly/#appendonly/g' /data/redis.conf")
        Host.run_script(address=host.address,
                        username=sys_user,
                        password=sys_pass,
                        script=host.commands.database(action='start'))
        Host.run_script(
            address=host.address,
            username=sys_user,
            password=sys_pass,
            script="sed -i 's/#appendonly/appendonly/g' /data/redis.conf")
        driver = RedisDriver(host, redis_port, redis_pass, redis_time_out)

        with driver.redis() as client:
            try:
                client.config_set("appendonly", "yes")
            except Exception, e:
                click.echo("Error while requesting dump: {}".format(e))
                return False
def restore_dst_database(dump_path, host, redis_port, redis_pass, sys_user,
                         sys_pass, remote_path, redis_time_out):

    from physical.models import Host
    click.echo("Restoring target database...")
    Host.run_script(address=host.address,
                    username=sys_user,
                    password=sys_pass,
                    script=host.commands.database(action='stop'))

    try:
        transport = paramiko.Transport((host, 22))
        transport.connect(username=sys_user, password=sys_pass)

        sftp = paramiko.SFTPClient.from_transport(transport)
        sftp.put(dump_path, remote_path)

        sftp.close()
        transport.close()
    except Exception, e:
        click.echo('ERROR while transporting dump file: {}'.format(e))
        return False
    try:
        transport = paramiko.Transport((host, 22))
        transport.connect(username=sys_user, password=sys_pass)

        sftp = paramiko.SFTPClient.from_transport(transport)
        sftp.put(dump_path, remote_path)

        sftp.close()
        transport.close()
    except Exception, e:
        click.echo('ERROR while transporting dump file: {}'.format(e))
        return False

    Host.run_script(
        address=host.address,
        username=sys_user,
        password=sys_pass,
        script="sed -i 's/appendonly/#appendonly/g' /data/redis.conf")
    Host.run_script(address=host.address,
                    username=sys_user,
                    password=sys_pass,
                    script=host.commands.database(action='start'))
    Host.run_script(
        address=host.address,
        username=sys_user,
        password=sys_pass,
        script="sed -i 's/#appendonly/appendonly/g' /data/redis.conf")

    driver = RedisDriver(host, redis_port, redis_pass, redis_time_out)

    with driver.redis() as client: