A robust cloud deployment means having a well thought out data management strategy. At CloudSigma we offer free functionality such as snapshotting as well as tiered storage. It’s therefore possible to implement a great data management framework to ensure strong protection for the availability and integrity of the data you store in the cloud.
In this post we share with you a script that allows you to automate promoting a snapshot of a drive into a full drive. This is great for backing up various restore points you have created with the drive backup functionality. This functionality is achieved using a python script, which in turn leverages the free CloudSigma Python Library (you can download this from here).
So let’s get started!
First you have to install python on your local machine or server if you don’t have that already. Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python version by default. Even some Windows computers now come with Python already installed. Here is a brief overview of installing Python for various operating systems.
Installation by OS
Mac OS X
1 |
sudo pip install cloudsigma |
Ubuntu
1 2 |
sudo apt-get -y install python-pip pip install cloudsigma |
CentOS / RHEL
In order to install the CloudSigma module, you first need to install the EPEL repository, in order to install PIP. The instructions below are for RHEL 6.x / CentOS 6.x. For further details on installing the repository, please visit the EPEL site at here.
1 2 3 4 5 |
yum install -y wget wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh epel-release-6-8.noarch.rpm yum install -y python-pip pip install cloudsigma |
Python and Script Configuration
Now let’s verify the python is installed correctly with this simple command:
1 |
python --version |
The output version of the above command should be similar to: Python 2.7.10
Once, you have python installed on your machine, we can proceed with py-cloudsigma
configuration.
In order for the CloudSigma library to interact with the API, you need to provide your credentials.
These are set in the file ~/.cloudsigma.conf
.
Here’s a sample version of the file that “communicates” to the San Jose data center. If you want instead to use the Zürich datacenter, simply replace sjc
with zrh
in the api_endpoint
and ws_endpoint
.
1 2 3 4 |
api_endpoint = https://sjc.cloudsigma.com/api/2.0/ ws_endpoint = wss://direct.sjc.cloudsigma.com/websocket username = <enter your account email> password = <enter your password> |
Since this file includes credentials, it’s highly recommended you set the permission of the file to chmod 600
so that this file can only be read by the owner:
1 |
chmod 600 ~/.cloudsigma.conf |
Now we are ready to create and execute the python script. We include the full source code below so just open your favourite text-editor and paste it there or use the download link here
Please be aware that the extension of the file must be .py
when you come to save the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/usr/bin/python import cloudsigma from pprint import pprint import time uid = raw_input("Snapshot UUID: ") snapshots = cloudsigma.resource.Snapshot() ssd_drive = snapshots.clone(uid) pprint(ssd_drive) time.sleep(10) drive = cloudsigma.resource.Drive() zadara_drive = drive.clone((ssd_drive['uuid']), {'storage_type': 'zadara'}) pprint(zadara_drive) zadara_ready = False while not zadara_ready: if drive.get(zadara_drive['uuid'])['status'] == 'unmounted': zadara_ready = True print "Done" drive.delete(ssd_drive['uuid']) else: time.sleep(1) |
Execute the script through the following command:
1 |
<script-name>.py |
The main goal of this script is to make things as convenient and easy as possible on the storage management side of things, especially for new users and for those who like the console more than GUI 🙂