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
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
Following execution, the API returns the new drive’s UUID, which we need for the final copy command:
The copy command requires two arguments, the DRIVE to which you are copying and the SOURCE of the copy;
Before executing, be sure both drives are unmounted. In this particular example, the call would be:
$ ./openhosting.sh drives/26df0e85-9f9b-4862-931b-
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
Copying is 52% percent done, and when it completes the copy will be bootable.