cancel
Showing results for 
Search instead for 
Did you mean: 

OneView backup

 
SOLVED
Go to solution
BradV
Trusted Contributor

OneView backup

I can successfully initiate a backup with: 

# Start a backup
declare -A BACKUPURI
BACKUPURI=($(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request POST ${OneView}/rest/backups | jq -r '.members[] | \"(.uri) \(/.taskUri) \(.downloadUri)"'))
echo "The uri of the backup is:    ${BACKUPURI[0]}"
echo "The uri of the task is:      ${BACKUPURI[1]}"
echo "The uri of the download is:  ${BACKUPURI[2]}"

except it is not returning any data.  If I just run piping to jq -r '.' nothing is output.  This used to work under 800.  Did something change in how to handle backups through the rest API?

7 REPLIES 7
ChrisLynchHPE
Neighborhood Moderator

Re: OneView backup

What API version are you trying to use?  You can still specify the older API with each of your API calls.  However, the property you are looking for isn't within the async task that is created you need to monitor.  In the async tasks completion, you would want to then get the backup file location from associatedResource.resourceUri:

{
    "type": "TaskResourceV2",
    "uri": "/rest/tasks/1D584F0C-96B6-4B19-94C9-8689B5A44A0A",
    "category": "tasks",
    "eTag": "19",
    "created": "2019-06-12T14:24:18.144Z",
    "modified": "2019-06-12T14:24:49.138Z",
    "taskStatus": "Backup completed and ready to download",
    "taskState": "Completed",
    "owner": "Administrator",
    "parentTaskUri": null,
    "userInitiated": true,
    "associatedTaskUri": null,
    "name": "Create backup",
    "taskErrors": [],
    "taskOutput": [],
    "progressUpdates": [],
    "totalSteps": 100,
    "completedSteps": 100,
    "percentComplete": 100,
    "expectedDuration": 0,
    "computedPercentComplete": 100,
    "data": null,
    "taskType": "User",
    "stateReason": "create-backup",
    "associatedResource": {
        "resourceName": "hpov5_backup_2019-06-12_142415",
        "resourceUri": "/rest/backups/appliance_backup_2019-06-12_142415",
        "resourceCategory": "backups",
        "associationType": "MANAGED_BY"
    },
    "hidden": false
}

// The following is the reply from GET /rest/backups/appliance_backup_2019-06-12_142415
{
    "type": "BACKUP",
    "uri": "/rest/backups/appliance_backup_2019-06-12_142415",
    "category": "backups",
    "eTag": null,
    "created": "2019-06-12T14:24:15.919Z",
    "modified": "2019-06-12T14:24:51.645Z",
    "id": "hpov5_backup_2019-06-12_142415",
    "percentComplete": 100,
    "hostName": "ci-00155d5fc035",
    "fullyQualifiedHostName": "appliance.domain.com",
    "userName": "Administrator",
    "errorMessage": "",
    "resolutionMessage": "",
    "resolutionKey": "",
    "resolutionParms": [],
    "errorKey": "",
    "errorParms": [],
    "firmwareVersionMajor": "4",
    "firmwareVersionMinor": "20",
    "hardwareModel": "HPE OneView VM",
    "platformType": "vm",
    "status": "SUCCEEDED",
    "backupSize": 14172176,
    "taskUri": "/rest/tasks/1D584F0C-96B6-4B19-94C9-8689B5A44A0A",
    "downloadUri": "/rest/backups/archive/appliance_backup_2019-06-12_142415",
    "downloadStatus": "NOT_DOWNLOADED",
    "downloadUserName": "",
    "downloadTime": "",
    "backupType": "ON_DEMAND",
    "compatibilityVersion": "4.20",
    "softwareVersion": "4.20.01-0380241",
    "uploadedFileName": "",
    "saveUri": "/rest/backups/remotearchive/appliance_backup_2019-06-12_142415",
    "saveStatus": "NOT_SAVED",
    "saveTaskUri": "",
    "saveUserName": "",
    "saveStartTime": "",
    "savePercentComplete": 0,
    "saveCancelUserName": "",
    "saveRemoteServerName": "",
    "compatibilityFamily": "HPE OneView VM",
    "cpu": 4,
    "memory": 16,
    "secureDataAtRest": false,
    "isApplianceEncryptionKeyValid": true,
    "aekId": "4659-4975-5857-7939",
    "backupStartTime": "2019-06-12T14:24:15.919Z"
}

 

 


Accept or Kudo

BradV
Trusted Contributor

Re: OneView backup

Hi Chris,

Using version 1000.  My problem is that even if I just run: 

curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request POST ${OneView}/rest/backups | jq -r '.'

I'm not getting anything back other than:

 % Total  % Received % Xferd Average Speed  Time  Time    Time   Current
                                                   Dload    Upload  Total  Spent   Left    Speed
 0         0    0      0        0        0          0            0 --:--:--  0:00:01 --:--:--     0

.  I'm logged in to the gui and I can see the backup process kicking off.  So, I know the  backup job is running.  I'm just not getting back any data to tell me the task uri.

ChrisLynchHPE
Neighborhood Moderator

Re: OneView backup

That output is from cURL uploading the file because you used the -f/-form switch.  Upon return of the upload, there will be an HTTP 202 status reply, which you then need to get the async task URI from the Location HTTP header.

Here is the Python example on the various ways to interact with appliance backup and restore methods.


Accept or Kudo

BradV
Trusted Contributor

Re: OneView backup

Hi Chris,

Where do I have --form?  I have:  --insecure, --header for api version, --header for session id, and --request POST.  I tried api versions 1000, 800, and 300.  Got the same non-response from all.  I am taking another look at the python and ansible libraries.

BradV
Trusted Contributor

Re: OneView backup

OK, got the syntax correct.  I had to include '--include' in order to see the response headers.  So, this kicks off the backup and gives me back the task uri: 

BACKUPURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --include \
     --request POST ${OneView}/rest/backups | grep Location | awk '{print $2}')
echo "The uri of the backup task is: ${BACKUPURI}"

Now, I just need to work on querying the task status and then downloading the backup. 

BradV
Trusted Contributor

Re: OneView backup

Making progress, but actually trying to retrieve the backup is failing.  I have: 

# Start a backup
#
BACKUPURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --include \
     --request POST ${OneView}/rest/backups | grep Location | awk '{print $2}')
BACKUPURI=${BACKUPURI%s'\r'}
echo "The uri of the backup task is: ${BACKUPURI}"
#
# Get status of the backup (this will give you status, etc):
curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${BACKUPURI} | jq -r '.assciatedResource.resourceUri, (. | {percentComplete,taskStatus,resourceUri})'
#
# Knowing that the backup is complete, we need the resource URI:
RESORCURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${BACKUPURI} | jq -r '.assciatedResource.resourceUri')
RESORCURI=${RESORCURI%s'\r'}
#
# Now, get the download location:
DOWNLOADLOC=$(curl --insecure \
     --include \
     --header "Accept: application/octetstream;q=0.8,application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}${DOWNLOADURI} | grep '^Location:' | awk '{ print $2 }")
DOWNLOADLOC=${DOWNLOADLOC%s'\r'}

When I try to actually get the download, I get: "curl: (3) Illegal characters found in URL"  Not sure what it is complaining about.  All of the characters in DOWNLOADLOC are ascii.  I am using: 

# Download the backup:
curl --insecure \
     --include \
     --header "Accept: application/octetstream;q=0.8,application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${DOWNLOADLOC}
BradV
Trusted Contributor
Solution

Re: OneView backup

Got it worked out.  Here is working code: 

# Follow instructions in: OneView-API_Get_Session_Credentials.txt
#
# Start a backup
#
BACKUPURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --include \
     --request POST ${OneView}/rest/backups | grep Location | awk '{print $2}')
BACKUPURI=${BACKUPURI%s'\r'}
echo "The uri of the backup task is: ${BACKUPURI}"
#
# Get status of the backup (repeat until task status is "Backup completed and ready to download."):
TASKSTATUS=''
while [[ ${TASKSTATUS} != *"completed and ready to download"* ]]; do
   TASKSTATUS=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${BACKUPURI} | jq -r '. | {taskStatus}')
   sleep 2
done
#
# Knowing that the backup is complete, we need the resource URI:
RESORCURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${BACKUPURI} | jq -r '.assciatedResource.resourceUri')
RESORCURI=${RESORCURI%s'\r'}
#
# Now, get the download URI:
DOWNLOADURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}${RESORCURI} | jq -r '.downloadUri')
#
# Now, get the download location:
DOWNLOADLOC=$(curl --insecure \
     --include \
     --header "Accept: application/octetstream;q=0.8,application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}${DOWNLOADURI} | grep '^Location:' | awk '{ print $2 }")
DOWNLOADLOC=$(echo "${DOWNLOADLOC}" | tr -d '\r')
DOWNLDFIL=$(echo "${DOWNLOADURI}" | cut -d/ -f5).bkp
#
# Download the backup:
curl --insecure \
     --fail \
     --location \
     --header "Accept: application/octetstream" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --output ${DOWNLDFIL} \
     --request GET ${DOWNLOADLOC}