世代管理しないSnapshotの作成
世代管理をしないSnapshotを作成するスクリプトを記載します。このスクリプトは、SnapOPCを使用した世代管理をしない差分データのバックアップを作成する運用で使用します。詳細は、SnapOPCを使用した世代管理をしない差分データのバックアップの作成を参照してください。
備考
スクリプト実行中は、Snapshotのデータの整合性を保証するために、業務VolumeのI/Oやアプリケーションの処理を瞬間的に停止させ、静止点を作成する必要があります。スクリプトの処理が完了したあとは、論理的な更新データのコピーは完了しているため、業務を再開させることができます。
スクリプトの処理の流れは以下です。
POST /volume/{volume_id}/snapshot APIを使用してSnapshotを作成する。
snapopc_create.py
import sys
from eternus_rest import EtdxBaseApi
# Change the following values for your environment.
storage_url = "https://192.168.0.1:5665"
storage_user_name = "username"
storage_password = "password"
# Change the following values as required.
# Volume ID to create snapshot.
volume_id = 100001
# TPP ID to create a snapshot.
tpp_id = 0
# Name of the snapshot.
snapshot_name = "snap#0"
class EtdxApi(EtdxBaseApi):
def __init__(self, base_url, boxid=None, proxies=None):
super().__init__(base_url, boxid=boxid, proxies=proxies)
def snapopc_create(self, volume_id, tpp_id, snapshot_name):
"""Create snapshot using SnapOPC.
Args:
volume_id (int): Volume ID to create snapshot.
tpp_id (int): TPP ID to create a snapshot.
snapshot_name (str): Name of the snapshot.
Returns:
int: Volume ID of the created snapshot. If failed, returns a value
of -1. This value cannot be used as volume ID.
"""
body = {
"name": snapshot_name,
"tpp_id": tpp_id,
"is_manual_snapshot": True
}
r = super().post("/api/v1/volume/{0!s}/snapshot".format(volume_id),
body)
if r.status_code != 202:
print("Failed to request a snapshot creation.")
print(r)
print(r.json())
return -1
# Wait for the job completion
job_r = super().wait_job(r.json()["job_id"])
if job_r.json()["status"] != "Success":
print("Failed to create a snapshot.")
print(job_r)
print(job_r.json())
return -1
backup_volume_href = job_r.json()["resource_href_list"][0]
backup_volume_id = int(backup_volume_href.split("/")[4])
return backup_volume_id
def main():
storage = EtdxApi(storage_url)
# Login
if not storage.login(storage_user_name, storage_password):
return False
print("Creating snapshot of the volume (ID: {0!s}) using SnapOPC."
.format(volume_id))
# Create snapshot
snapshot_volume_id = storage.snapopc_create(volume_id, tpp_id,
snapshot_name)
if snapshot_volume_id == -1:
return False
print("Created volume ID of snapshot:", snapshot_volume_id)
# Get the snapshot information
r = storage.get("/api/v1/volume/{0!s}/copysession"
.format(snapshot_volume_id))
print(r.json())
# Logout
storage.logout()
return True
if __name__ == '__main__':
if not main():
sys.exit(1)

