def cli(host_cluster_db):
    """
    This will initiate an on demand archive log backup of the database.

\b
    The source database is specified in a host:db format.
\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name.
\b
    Returns:
        log_backup_info (dict): The information about the snapshot returned from the Rubrik CDM.
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(
        cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    oracle_db_id = rbk.get_oracle_db_id(rubrik, host_cluster_db[1],
                                        host_cluster_db[0])
    oracle_log_backup_info = rbk.oracle_log_backup(rubrik, oracle_db_id)
    cluster_timezone = pytz.timezone(timezone)
    utc = pytz.utc
    start_time = utc.localize(
        datetime.datetime.fromisoformat(oracle_log_backup_info['startTime']
                                        [:-1])).astimezone(cluster_timezone)
    fmt = '%Y-%m-%d %H:%M:%S %Z'
    print("Oracle Log Backup {} \nStatus: {}, Started at {}.".format(
        oracle_log_backup_info['id'], oracle_log_backup_info['status'],
        start_time.strftime(fmt)))
    return oracle_log_backup_info
Ejemplo n.º 2
0
def cli(host_cluster_db, force):
    """
    This will unmount a Rubrik live mount using the database name and the live mount host.

\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name
        force (bool): Force the unmount
\b
    Returns:
        unmount_info (dict): Status of the unmount request.
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    live_mount_ids = rbk.get_oracle_live_mount_id(rubrik, cluster_info['id'], host_cluster_db[1], host_cluster_db[0])
    if not live_mount_ids:
        raise RubrikOracleUnmountError("No live mounts found for {} live mounted on {}. ".format(host_cluster_db[1], host_cluster_db[0]))
    else:
        unmount_info = []
        for live_mount_id in live_mount_ids:
            unmount_response = rbk.live_mount_delete(rubrik, live_mount_id, force)
            print("Live mount id: {} Unmount status: {}.".format(live_mount_id, unmount_response['status']))
            unmount_info.append(unmount_response)
        return unmount_info
def cli(host_cluster_db, target_host, time_restore):
    """Live mount a Rubrik Oracle Backup.

\b
    Gets the backup for the Oracle database on the Oracle database host and will live mount it on the host provided.
\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name
        target_host (str): The host to live mount the database. (Must be a compatible Oracle host on Rubrik)
        time_restore: The point in time for the live mount iso 8601 format (2019-04-30T18:23:21)
\b
    Returns:
        live_mount_info (json); JSON text file with the Rubrik cluster response to the live mount request
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(
        cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    oracle_db_id = rbk.get_oracle_db_id(rubrik, host_cluster_db[1],
                                        host_cluster_db[0])
    oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
    # If source DB is RAC then the target for the live mount must be a RAC cluster
    if 'racName' in oracle_db_info.keys():
        if oracle_db_info['racName']:
            host_id = rbk.get_rac_id(rubrik, cluster_info['id'], target_host)
    else:
        host_id = rbk.get_host_id(rubrik, cluster_info['id'], target_host)
    if time_restore:
        time_ms = rbk.epoch_time(time_restore, timezone)
        print("Using {} for mount.".format(time_restore))
    else:
        print("Using most recent recovery point for mount.")
        oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
        time_ms = rbk.epoch_time(oracle_db_info['latestRecoveryPoint'],
                                 timezone)
    print("Starting Live Mount of {} on {}.".format(host_cluster_db[1],
                                                    target_host))
    live_mount_info = rbk.live_mount(rubrik, oracle_db_id, host_id, time_ms)
    # Set the time format for the printed result
    cluster_timezone = pytz.timezone(timezone)
    utc = pytz.utc
    start_time = utc.localize(
        datetime.datetime.fromisoformat(
            live_mount_info['startTime'][:-1])).astimezone(cluster_timezone)
    fmt = '%Y-%m-%d %H:%M:%S %Z'
    print("Live mount status: {}, Started at {}.".format(
        live_mount_info['status'], start_time.strftime(fmt)))
    return json.dumps(live_mount_info)
Ejemplo n.º 4
0
def cli(host_cluster_db):
    """
    Displays information about the Oracle database object, the available snapshots, and recovery ranges.

\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name
\b
    Returns:
        None: Information is printed to standard out
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("")
    print("*" * 100)
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    oracle_db_id = rbk.get_oracle_db_id(rubrik, host_cluster_db[1], host_cluster_db[0])
    oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
    print("*" * 100)
    print("Database Details: ")
    print("Database name: {}   ID: {}".format(oracle_db_info['name'], oracle_db_info['id']))
    if 'standaloneHostName' in oracle_db_info.keys():
        print("Host Name: {}".format(oracle_db_info['standaloneHostName']))
    elif 'racName' in oracle_db_info.keys():
        print("Rac Cluster Name: {}    Instances: {}".format(oracle_db_info['racName'], oracle_db_info['numInstances']))
    print("SLA: {}    Log Backup Frequency: {} min.    Log Retention: {} hrs.".format(oracle_db_info['effectiveSlaDomainName'], oracle_db_info['logBackupFrequencyInMinutes'], oracle_db_info['logRetentionHours']))
    oracle_snapshot_info = rbk.get_oracle_db_snapshots(rubrik, oracle_db_id)
    print("*" * 100)
    print("Available Database Backups (Snapshots):")
    for snap in oracle_snapshot_info['data']:
        print("Database Backup Date: {}   Snapshot ID: {}".format(rbk.cluster_time(snap['date'], timezone), snap['id']))
    oracle_db_recoverable_range_info = rbk.get_oracle_db_recoverable_range(rubrik,  oracle_db_id)
    print("*" * 100)
    print("Recoverable ranges:")
    for recovery_range in oracle_db_recoverable_range_info['data']:
        print("Begin Time: {}   End Time: {}".format(rbk.cluster_time(recovery_range['beginTime'], timezone)[:-6],
                                                     rbk.cluster_time(recovery_range['endTime'], timezone)[:-6]))
def cli(host_cluster_db, force, sla):
    """
    This will initiate an on demand snapshot (backup) of the database.

\b
    The source database is specified in a host:db format. To force a new full level 0
    image backup of the database set force to True. If you would like to use a different SLA for this snapshot you
    can specify that here also. Note if no SLA is supplied the current sla for this database will be used.
\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name.
        force (bool): Force a new full database image level 0 backup
        sla (str): The Rubrik SLA Domain to use if different than the assigned SLA
\b
    Returns:
        snapshot_info (dict): The information about the snapshot returned from the Rubrik CDM.
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    oracle_db_id = rbk.get_oracle_db_id(rubrik, host_cluster_db[1], host_cluster_db[0])
    if sla:
        oracle_db_sla_id = rbk.get_sla_id(rubrik, sla)
    else:
        oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
        oracle_db_sla_id = oracle_db_info['effectiveSlaDomainId']
    oracle_snapshot_info = rbk.oracle_db_snapshot(rubrik, oracle_db_id, oracle_db_sla_id, force)
    cluster_timezone = pytz.timezone(timezone)
    utc = pytz.utc
    start_time = utc.localize(datetime.datetime.fromisoformat(oracle_snapshot_info['startTime'][:-1])).astimezone(
        cluster_timezone)
    fmt = '%Y-%m-%d %H:%M:%S %Z'
    print("Oracle Database snapshot {} \nStatus: {}, Started at {}.".format(oracle_snapshot_info['id'], oracle_snapshot_info['status'], start_time.strftime(fmt)))
    return oracle_snapshot_info
def cli(host_cluster_db, path, time_restore, target_host):
    """
    This will mount the requested Rubrik Oracle backup set on the provided path.

\b
    The source database is specified in a host:db format. The mount path is required. If the restore time is not
    provided the most recent recoverable time will be used. The host for the mount can be specified if it is not it
    will be mounted on the source host. If the source database is on a RAC cluster the target must be a RAC cluster.
\b
    Args:
        host_cluster_db (str): The hostname the database is running on : The database name.
        path (str): The path for the mount. This must exist on the requested host.
        time_restore (str): The point in time for the backup set in  iso 8601 format (2019-04-30T18:23:21).
        target_host (str): The host to mount the backup set. If not specified the source host will be used.
                            IF source DB in on RAC this must be a RAC Cluster.
\b
    Returns:
        live_mount_info (dict): The information about the requested files only mount returned from the Rubrik CDM.
    """
    rubrik = rbk.connect_rubrik()
    cluster_info = rbk.get_cluster_info(rubrik)
    timezone = cluster_info['timezone']['timezone']
    print("Connected to cluster: {}, version: {}, Timezone: {}.".format(
        cluster_info['name'], cluster_info['version'], timezone))
    host_cluster_db = host_cluster_db.split(":")
    oracle_db_id = rbk.get_oracle_db_id(rubrik, host_cluster_db[1],
                                        host_cluster_db[0])
    oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
    # If not target host is provide mount the backup pieces on the source database host
    if not target_host:
        target_host = host_cluster_db[0]
    # If the source database is on a RAC cluster the target must be a RAC cluster otherwise it will be an Oracle Host
    if 'racName' in oracle_db_info.keys():
        if oracle_db_info['racName']:
            host_id = rbk.get_rac_id(rubrik, cluster_info['id'], target_host)
    else:
        host_id = rbk.get_host_id(rubrik, cluster_info['id'], target_host)
    # Use the provided time or if no time has been provided use the teh most recent recovery point
    if time_restore:
        time_ms = rbk.epoch_time(time_restore, timezone)
        print("Using {} for mount.".format(time_restore))
    else:
        print("Using most recent recovery point for mount.")
        oracle_db_info = rbk.get_oracle_db_info(rubrik, oracle_db_id)
        time_ms = rbk.epoch_time(oracle_db_info['latestRecoveryPoint'],
                                 timezone)
    print("Starting the mount of the requested {} backup pieces on {}.".format(
        host_cluster_db[1], target_host))
    live_mount_info = rbk.live_mount(rubrik,
                                     oracle_db_id,
                                     host_id,
                                     time_ms,
                                     files_only=True,
                                     mount_path=path)
    cluster_timezone = pytz.timezone(timezone)
    utc = pytz.utc
    start_time = utc.localize(
        datetime.datetime.fromisoformat(
            live_mount_info['startTime'][:-1])).astimezone(cluster_timezone)
    fmt = '%Y-%m-%d %H:%M:%S %Z'
    print("Live mount status: {}, Started at {}.".format(
        live_mount_info['status'], start_time.strftime(fmt)))
    return live_mount_info