1 2 Previous Next 21 Replies Latest reply on May 30, 2018 8:50 AM by aleex42

    schedule VCSA 6.5 backups..

    sushilkm Enthusiast

      I was wondering if there is any script or similiar available to schedule VCSA backups to a FTP server.

       

      I tried multiple stuff but none seems to be working . Adapted a Bash script but it doesn't give me output as below

      VMware vSphere 6.5 Documentation Library

      Capture.PNG

       

      Tried Backup vCenter Server Appliance (VCSA) 6.5 Using PowerShell – VCDX56 

       

      But https://www.brianjgraf.com/2016/11/18/vsphere-6-5-automate-vcsa-backup/  the link at end on guthub is missing . Page missing...

       

      Is there a way to schedule these backups for VCSA.

        • 1. Re: schedule VCSA 6.5 backups..
          daphnissov Guru
          vExpertCommunity Warriors

          If you tried the script that was provided but it's not working, then let's identify why it's failing because the method provided in the docs does work for scheduled backups via cron.

          • 2. Re: schedule VCSA 6.5 backups..
            sushilkm Enthusiast

            Thanks. Yeah does make sense...So i followed the exact instruction as below

            VMware vCSA 6.5 Scheduled Backup – The vGoodie-bag

            Script does nothing. i am running it manually at the moment Or is it so that this will Run only via Cron job & cannot be invoked manually

             

            Output is as below . I am backing up to a FTP server.

            Capture.PNG

            • 3. Re: schedule VCSA 6.5 backups..
              daphnissov Guru
              Community WarriorsvExpert

              Can you please show your script content?

              • 4. Re: schedule VCSA 6.5 backups..
                sushilkm Enthusiast

                Here is the copy paste of same . I have just edited the user variable in below. 

                 

                root@mxxxxxxxxxx [ /usr/local/bin ]# cat backup.sh

                #!/bin/bash

                ##### EDITABLE BY USER to specify vCenter Server instance and backup destination. #####

                VC_ADDRESS=xxxxxxxxx.vcname.com

                VC_USER=administrator@vsphere.local

                VC_PASSWORD=secretpassword

                FTP_ADDRESS=192.168.10.11

                FTP_USER=vcbackup

                FTP_PASSWORD=secretcode

                BACKUP_FOLDER=/VMware-Backups/vCenter-APPS/

                ############################

                 

                 

                # 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":"FTPS",

                          //"location_type":"SCP",

                          "comment":"Automatic backup",

                          "parts":["seat"],

                          "location":"ftp://$FTP_ADDRESS/$BACKUP_FOLDER/$TIME",

                          //"location":"scp://$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

                root@xxxxxx [ /usr/local/bin ]#

                 

                 

                Once run, i get the below output

                root@xxxxxxx [ /usr/local/bin ]# /usr/local/bin/backup.sh

                {"value":"286df91b94eb696cad1c02bfdcbc6b42"}Backup job id:

                  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                                 Dload  Upload   Total   Spent    Left  Speed

                100    63    0    63    0     0    301      0 --:--:-- --:--:-- --:--:--   301

                Backup job state:

                 

                 

                Backup job completion status:

                root@xxxxxxxxxxxx [ /usr/local/bin ]# cat backup.sh

                • 5. Re: schedule VCSA 6.5 backups..
                  sushilkm Enthusiast

                  Not sure it helps or not but below is output of backup.sh log

                   

                  /usr/local/bin ]# cat backup.log

                  Starting backup 2018-05-29-00-50-04

                    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                                   Dload  Upload   Total   Spent    Left  Speed

                  100   580    0   159  100   421   7069  18719 --:--:-- --:--:-- --:--:-- 19136

                  {"name":"com.vmware.vapi.rest.badRequest","localizableMessages":[{"defaultMessage":"Bad Request","id":"com.vmware.vapi.rest.badRequest"}],"majorErrorCode":400}

                  {"value":["20180429-061109-7515524","20180422-075341-7515524"]}

                   

                   

                  Starting backup 2018-05-29-00-51-06

                    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                                   Dload  Upload   Total   Spent    Left  Speed

                  100   580    0   159  100   421  10677  28272 --:--:-- --:--:-- --:--:-- 30071

                  {"name":"com.vmware.vapi.rest.badRequest","localizableMessages":[{"defaultMessage":"Bad Request","id":"com.vmware.vapi.rest.badRequest"}],"majorErrorCode":400}

                  {"value":["20180429-061109-7515524","20180422-075341-7515524"]}

                   

                   

                  Starting backup 2018-05-29-00-56-12

                    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                                   Dload  Upload   Total   Spent    Left  Speed

                  100   584    0   159  100   425   9850  26328 --:--:-- --:--:-- --:--:-- 26562

                  {"name":"com.vmware.vapi.rest.badRequest","localizableMessages":[{"defaultMessage":"Bad Request","id":"com.vmware.vapi.rest.badRequest"}],"majorErrorCode":400}

                  {"value":["20180429-061109-7515524","20180422-075341-7515524"]}

                  • 6. Re: schedule VCSA 6.5 backups..
                    daphnissov Guru
                    vExpertCommunity Warriors

                    Change the value of VC_ADDRESS to be "localhost" instead of FQDN. Change the value of VC_USER to be just "administrator" and not with the "@vsphere.local" part and run the script again.

                    • 7. Re: schedule VCSA 6.5 backups..
                      sushilkm Enthusiast

                      /usr/local/bin ]# /usr/local/bin/backup.sh

                      {"type":"com.vmware.vapi.std.errors.unauthenticated","value":{"messages":[{"args":[],"default_message":"Authentication required.","id":"com.vmware.vapi.endpoint.method.authentication.required"}]}}Backup job id:

                        % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                                       Dload  Upload   Total   Spent    Left  Speed

                      100   188    0   188    0     0  11368      0 --:--:-- --:--:-- --:--:-- 11750

                      Backup job state:

                       

                       

                      Backup job completion status:

                       

                      Thais how it looks below

                       

                      #!/bin/bash

                      ##### EDITABLE BY USER to specify vCenter Server instance and backup destination. #####

                      VC_ADDRESS=localhost

                      VC_USER=administrator

                      VC_PASSWORD=topsecret

                      FTP_ADDRESS=192..168.1.10

                      FTP_USER=vcbackup

                      FTP_PASSWORD=topsercte

                      BACKUP_FOLDER=/VMware-Backups/vCenter-APPS/

                      I am thinking if we need to use local :root: user.

                      • 8. Re: schedule VCSA 6.5 backups..
                        daphnissov Guru
                        vExpertCommunity Warriors

                        Although I don't think it's the cause, your FTP address has two dots separating first and second octets.

                        • 9. Re: schedule VCSA 6.5 backups..
                          sushilkm Enthusiast

                          Ah. that happened while i pasted the code here to protect my actual FTP IP

                          JUst double checked on script.. it is correct

                          • 10. Re: schedule VCSA 6.5 backups..
                            daphnissov Guru
                            Community WarriorsvExpert

                            Check your vAPI service. Is it started or does it have a status other than good?

                            • 11. Re: schedule VCSA 6.5 backups..
                              sushilkm Enthusiast

                              Looks good to me , unless i am missing some thing

                               

                              service-control --status

                              Running:

                              applmgmt lwsmd vmafdd vmonapi vmware-cm vmware-content-library vmware-eam vmware-perfcharts vmware-rhttpproxy vmware-sca vmware-sps vmware-statsmonitor vmware-updatemgr vmware-vapi-endpoint vmware-vmon vmware-vpostgres vmware-vpxd vmware-vpxd-svcs vmware-vsan-health vmware-vsm vsphere-client vsphere-ui

                              Stopped:

                              vmcam vmware-imagebuilder vmware-mbcs vmware-netdumper vmware-rbd-watchdog vmware-vcha

                              root@xxxxxxxxxxx [ ~ ]# service-control --status vmware-vapi-endpoint

                              Running:

                              vmware-vapi-endpoint

                               

                              Here is teh status checkl... All green.

                               

                              <healthStatus xmlns="http://www.vmware.com/cis/cm/common/jaxb/healthstatus" schemaVersion="1.0">

                              <status>GREEN</status>

                               

                               

                              <message messageKey="com.vmware.vapi.endpoint.healthStatusProducedTimes" defaultMessage="Current vApi Endpoint health status is created between 2018-05-29T12:52:57PDT and 2018-05-29T12:52:58PDT.">

                               

                               

                              <param xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">2018-05-29T12:52:57PDT</param>

                               

                              <param xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">2018-05-29T12:52:58PDT</param>

                              </message>

                              </healthStatus>

                              • 12. Re: schedule VCSA 6.5 backups..
                                daphnissov Guru
                                Community WarriorsvExpert

                                Restart the applmgmt service on the vCenter, wait a few minutes, and try again.

                                • 13. Re: schedule VCSA 6.5 backups..
                                  daphnissov Guru
                                  Community WarriorsvExpert

                                  And to confirm, you can use "administrator@vsphere.local" for the VC_USER variable just fine. I was actually getting similar failures with no apparent cause. The login token was generated, but the REST request to the backup service was not accepting the token. I rebooted the entire appliance but think it only required the applmgmt service be cycled.

                                  • 14. Re: schedule VCSA 6.5 backups..
                                    aleex42 Enthusiast
                                    vExpert

                                    I've modified the orginal backup script to perfectly work with an cron schedule:

                                     

                                    https://blog.krogloth.de/vcsa-backup/

                                     

                                    Replacing "scp" with "ftp" should work for you.

                                     

                                    And if you could: upgrading to vSphere 6.7 will fix this issue, too - because there you can schedule the backup in the vCenter Appliance Management. Find a screenshot linked in my blog post above.

                                     

                                    Hope to help

                                     

                                    Alex

                                    1 2 Previous Next