How To

API Quickies – How to Copy a Drive

Around these parts, we eat our own dog food. The dashboard, for example, interacts with the API just as you might. Consider the drive copy command, which is triggered by clicking the yellow “copy” button on any unmounted drive.

Behind the scenes, the dashboard issues two API calls. The first API call creates a blank drive of equal size to the one you wish to copy. And, the second API call copies the contents of the original to the new drive.

The demo@openhosting account contains a drive called “source-drive.” To create a copy of this drive we need to know it’s UUID and size. A simple call to the API returns this information for all drives in the account:

They are otherwise normal and yours to do with as you wish. And, you might benefit from taking the following actions:

$ ./openhosting.sh drives/info

status active

name source-drive

drive 1181a421-e490-47c7-96a4-b29b5d6abe44

encryption:cipher aes-xts-plain

user d2d23ab0-4b3f-4b73-858f-4d2c9c2262c4

size 1073741824

Alternatively, by pressing the “configure” button on the dashboard, the drive’s UUID is displayed just above the name.

Now to create a drive of the same size using an API call documented on our API page:

$ ./openhosting.sh -c drives/create << EOF

name source-drive-copy

size 1073741824

EOF

Following execution, the API returns the new drive’s UUID, which we need for the final copy command:

status active

name source-drive-copy

read:bytes 4096

write:bytes 4096

drive 26df0e85-9f9b-4862-931b-644a31dd7df7

encryption:cipher aes-xts-plain

user d2d23ab0-4b3f-4b73-858f-4d2c9c2262c4

read:requests 1

write:requests 1

size 1073741824

The copy command requires two arguments, the DRIVE to which you are copying and the SOURCE of the copy;

./openhosting.sh drives/DRIVE/image/SOURCE[/CONVERSION]

Before executing, be sure both drives are unmounted. In this particular example, the call would be:

$ ./openhosting.sh drives/26df0e85-9f9b-4862-931b-

44a31dd7df7/image/1181a421-e490-47c7-96a4-b29b5d6abe44

This call produces no response. You can can check on the status of the copy by checking the dashboard or asking the API:

$ ./openhosting.sh drives/26df0e85-9f9b-4862-931b-644a31dd7df7/info

status active

name source-drive

read:bytes 1182932992

user d2d23ab0-4b3f-4b73-858f-4d2c9c2262c4

write:bytes 1643388928

drive 26df0e85-9f9b-4862-931b-644a31dd7df7

encryption:cipher aes-xts-plain

imaging 52%

read:requests 288802

claimed 0003eba7-21ba-4dfc-9f69-3137c6c13937:imaging:30476

write:requests 401620

size 1073741824

Copying is 52% percent done, and when it completes the copy will be bootable.

Get In Touch At sales@openhosting.com To Start Your Free Trial.