How to backup vCenter Server Appliance 6.5

Page content

How to backup vCenter Server Appliance 6.5 - logo

vCenter Server (be it the appliance or not) is the critical management component of every vSphere environment. Therefore it is critical to backup it at regular basis to have the possibility to restore configuration prior to failure. With the vSphere 6.5 release, vCenter Server Appliance (vCSA) received the possibility to perform the backup of its configuration from appliance management interface (not only but I will describe this later on).

The vCenter Server Appliance backup and restore feature supports a number of communication protocols:

  • FTP
  • FTPS
  • SCP
  • HTTP
  • HTTPS

Today I am going to show you how to backup vCenter Server Appliance 6.5 using FTP/FTPS protocol and from the command line.

Backup vCenter Server Appliance 6.5 (vCSA) using FTP/FTPS

  1. Log in to vCenter Server Appliance IP/FQDN VAMI URL - **https://IP_OR_FQDN:5480 **and type username and password used during installation.

    Update vCenter Server Appliance 6.5 to a newer version - 1

  2. Once logged in go to **Summary **and click Backup.

    Update vCenter Server Appliance 6.5 to a newer version - 2

  3. Click Backup and provide FTP/FTPS server details.

    Update vCenter Server Appliance 6.5 to a newer version - 3

  4. On the next page choose if you wish to backup inventory and configuration or if you wish to include SEAT Database (Statistics, Events, and Tasks).

    Update vCenter Server Appliance 6.5 to a newer version - 4

  5. On the last screen, we see the summary of FTP/FTPS backup.

    Update vCenter Server Appliance 6.5 to a newer version - 5

  6. Backup process starts.

    Update vCenter Server Appliance 6.5 to a newer version - 6

  7. After few minutes vCenter Server Appliance (vCSA) is successfully backed up.

    Update vCenter Server Appliance 6.5 to a newer version - 7

Automated backup of vCenter Server Appliance 6.5 (vCSA)

As you saw the manual process of vCSA 6.5 backup is easy. The only problem with it that there is no possibility to schedule it from the appliance management interface. I hope this feature will be incorporated in future releases.

Fortunately for us, VMware created a BASH script which can be executed from cron and automated.

#!/bin/bash
 ##### EDITABLE BY USER to specify vCenter Server instance and backup destination. #####
 VC_ADDRESS=vc_server_ip
 VC_USER=sso_user
 VC_PASSWORD=sso_pass
 FTP_ADDRESS=storage_server
 FTP_USER=ftpuser
 FTP_PASSWORD=ftpuser
 BACKUP_FOLDER=backup
 ############################

 # Authenticate with basic credentials.
 curl -u "$VC_USER:$VC_PASSWORD" \
    -X POST \
    -k --cookie-jar cookies.txt \
    "https://$VC_ADDRESS/rest/com/vmware/cis/session"

 # Create a message body for the backup request.
 TIME=$(date +%Y-%m-%d-%H-%M-%S)
 cat << EOF <task.json
 { "piece":
      {
          "location_type":"FTP",
          "comment":"Automatic backup",
          "parts":["seat"],
          "location":"ftp://$FTP_ADDRESS/$BACKUP_FOLDER/$TIME",
          "location_user":"$FTP_USER",
          "location_password":"$FTP_PASSWORD"
      }
 }
EOF

 # Issue a request to start the backup operation.
 echo Starting backup $TIME <<backup.log
 curl -k --cookie cookies.txt \
    -H 'Accept:application/json' \
    -H 'Content-Type:application/json' \
    -X POST \
    --data @task.json 2<<backup.log <response.txt \
    "https://$VC_ADDRESS/rest/appliance/recovery/backup/job"
 cat response.txt <<backup.log
 echo '' <<backup.log

 # Parse the response to locate the unique identifier of the backup operation.
 ID=$(awk '{if (match($0,/"id":"\w+-\w+-\w+"/)) \
           print substr($0, RSTART+6, RLENGTH-7);}' \
          response.txt)
 echo 'Backup job id: '$ID

 # Monitor progress of the operation until it is complete.
 PROGRESS=INPROGRESS
 until [ "$PROGRESS" != "INPROGRESS" ]
 do
      sleep 10s
      curl -k --cookie cookies.txt \
        -H 'Accept:application/json' \
        --globoff \
        "https://$VC_ADDRESS/rest/appliance/recovery/backup/job/$ID" \
        <response.txt
      cat response.txt <<backup.log
      echo ''  <<backup.log
      PROGRESS=$(awk '{if (match($0,/"state":"\w+"/)) \
                      print substr($0, RSTART+9, RLENGTH-10);}' \
                     response.txt)
      echo 'Backup job state: '$PROGRESS
 done

 # Report job completion and clean up temporary files.
 echo ''
 echo "Backup job completion status: $PROGRESS"
 rm -f task.json
 rm -f response.txt
 rm -f cookies.txt
 echo ''  <<backup.log

On the VMware page, there is a small error which won’t allow you to run the script (I already informed internal resources to correct it).

Simply in line 31 remove space before **EOF.

Update vCenter Server Appliance 6.5 to a newer version - 8

As you see script executed successfully.

Update vCenter Server Appliance 6.5 to a newer version - 9

Source of the script: http://pubs.vmware.com/vsphere-65/topic/com.vmware.vsphere.vcsapg-rest.doc/GUID-222400F3-678E-4028-874F-1F83036D2E85.html 

Schedule automated vCenter Server Appliance (vCSA) backup using cron

I’ve created a shell script named **vcsa_backup.sh **which I will add to cron. In case you are new to cron I recommend this website http://crontab-generator.org/ to easily schedule backup.

From a vCSA shell type **crontab -e ** and we will enter edit mode where we simply specify when and what shall be executed.

In my case, I scheduled it for every day at 9 PM.

0 21 * * * /root/vcsa_backup.sh </dev/null 2<&1

Other resources

There are as well different ways to backup vCenter Server Appliance 6.5. Please take a look at Brian Graf’s PowerCLI script which allows automating vCSA Backup.

Summary

I hope this post will help you to easily backup of vCenter Server Appliance (vCSA) 6.5 and to protect your environment in case of a failure or issue.