ONTAP Rest API Discussions

NetApp API for snapshot restore

Elan_LV
1,043 Views

Hi Everyone,

 Please could someone help me with API script to DB volume restore from the latest snapshot.

1 ACCEPTED SOLUTION

ddegraaf
1,009 Views

Sure, can you try something like this to restore a volume from the latest snapshot.

# Specify the uuid of the volume
vol_uuid = 'your_volume_uuid'
snapshot_name = None  # Set to None to use the latest snapshot

# Find the snapshot
snapshots = Snapshot.get_collection(vol_uuid)

latest_snapshot = None
latest_snapshot_time = 0
for snapshot in snapshots:
    if latest_snapshot == None or snapshot.create_time > latest_snapshot_time:
        latest_snapshot_time = snapshot.create_time
        latest_snapshot = snapshot

snapshot_name = latest_snapshot.name

# Restore the volume from the snapshot
vol = Volume(uuid=vol_uuid)
vol.patch(**{'restore_to.snapshot.name': snapshot_name})

 

Here is a previous discussion on just restoring from a given snapshot: https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Snapshot-Restore/td-p/159284

View solution in original post

1 REPLY 1

ddegraaf
1,010 Views

Sure, can you try something like this to restore a volume from the latest snapshot.

# Specify the uuid of the volume
vol_uuid = 'your_volume_uuid'
snapshot_name = None  # Set to None to use the latest snapshot

# Find the snapshot
snapshots = Snapshot.get_collection(vol_uuid)

latest_snapshot = None
latest_snapshot_time = 0
for snapshot in snapshots:
    if latest_snapshot == None or snapshot.create_time > latest_snapshot_time:
        latest_snapshot_time = snapshot.create_time
        latest_snapshot = snapshot

snapshot_name = latest_snapshot.name

# Restore the volume from the snapshot
vol = Volume(uuid=vol_uuid)
vol.patch(**{'restore_to.snapshot.name': snapshot_name})

 

Here is a previous discussion on just restoring from a given snapshot: https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Snapshot-Restore/td-p/159284

Public