1 2 Previous Next 21 Replies Latest reply on May 30, 2018 8:50 AM by aleex42 Go to original post
      • 15. Re: schedule VCSA 6.5 backups..
        sushilkm Enthusiast

        Thanks Sir. But it seems that only option is to raise a case with TAC. I recycled the appliance and it still throws same error.

         

        Tried the script that alex suggested and it;s becoming a uphill task.  you might want to fix the /home/vmware/ on line 29 as i could not find that find that path in mine appliance. below is error i got.

         

        backup1.sh

        /usr/local/bin/backup1.sh: line 29: cd: /home/vmware/: No such file or directory

        /usr/local/bin/backup1.sh: line 37: log/task-172.27.67.25.json: No such file or directory

        /usr/local/bin/backup1.sh: line 50: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 51: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 57: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 58: log/backup-172.27.67.25.log: No such file or directory

        awk: cmd. line:1: fatal: cannot open file `log/response-172.27.67.25.txt' for reading (No such file or directory)

        /usr/local/bin/backup1.sh: line 62: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 69: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 71: log/response-172.27.67.25.txt: No such file or directory

        /usr/local/bin/backup1.sh: line 76: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 77: log/backup-172.27.67.25.log: No such file or directory

        awk: cmd. line:1: fatal: cannot open file `log/response-172.27.67.25.txt' for reading (No such file or directory)

        /usr/local/bin/backup1.sh: line 79: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 82: log/backup-172.27.67.25.log: No such file or directory

        /usr/local/bin/backup1.sh: line 83: log/backup-172.27.67.25.log: No such file or directory

        Here is the customized script i used from your github repository.

        #!/bin/bash

         

         

         

         

        # --

        #Backup VMware VCSA

        # --

        # Copyright (C) 2018 Alexander Krogltoh, E-Mail: git <at > krogloth.de

        # --

        # This software comes with ABSOLUTELY NO WARRANTY. For details, see

        # the enclosed file COPYING for license information (GPL). If you

        # did not receive this file, see http://www.gnu.org/licenses/gpl.txt.

        # --

         

         

        # modified and bugfixed version of

        # https://pubs.vmware.com/vsphere-6-5/index.jsp?topic=%2Fcom.vmware.vsphere.vcsapg-rest.doc%2FGUID-222400F3-678E-4028-874F-1F83036D2E85.html

        # official VMware VCSA backup script

         

         

        VC_ADDRESS="192.168.1.1"

        VC_USER="administrator@vsphere.local"

        VC_PASSWORD="Topsecret!"

        FTP_ADDRESS="ftp://192.168.1.2./VMware-Backups/vCenter-APPS/"

        FTP_USER="vcbackup"

        FTP_PASSWORD="topsecret"

         

         

        BACKUP_LOG="log/backup-$VC_ADDRESS.log"

        COOKIES="log/cookies-$VC_ADDRESS.txt"

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

         

         

        cd /var/vmware/

         

         

        curl -u "$VC_USER:$VC_PASSWORD" \

           -X POST -s \

           -k --cookie-jar $COOKIES \

           "https://$VC_ADDRESS/rest/com/vmware/cis/session" 2>&1 >/dev/null

         

         

        TIME=$(date +%Y-%m-%d-%H-%M-%S)

        cat << EOF >log/task-$VC_ADDRESS.json

        { "piece":

             {

                 "location_type":"FTP",

                 "comment":"Automatic backup",

                 "parts":["seat"],

                 "location":"ftp://$FTP_ADDRESS/home/vmware/data/$VC_ADDRESS/$TIME",

                 "location_user":"$FTP_USER",

                 "location_password":"$SCP_PASSWORD"

             }

        }

        EOF

         

         

        echo Starting backup $TIME >>$BACKUP_LOG

        curl -k --cookie $COOKIES \

           -H 'Accept:application/json' \

           -H 'Content-Type:application/json' \

           -X POST \

           --data @log/task-$VC_ADDRESS.json 2>>$BACKUP_LOG >log/response-$VC_ADDRESS.txt \

           "https://$VC_ADDRESS/rest/appliance/recovery/backup/job"

        cat log/response-$VC_ADDRESS.txt >>$BACKUP_LOG

        echo '' >>$BACKUP_LOG

         

         

        ID=$(awk 'BEGIN{ FS=":" ; RS="," } $1 ~ "id" { ID = $2 } END { print ID }' log/response-$VC_ADDRESS.txt | sed "s/[\"}]//g" | tr -d "\n\r")

         

         

        echo 'Backup job id: '$ID >>$BACKUP_LOG

         

         

        PROGRESS="INPROGRESS"

        ROUND="1"

        until [ "$PROGRESS" != "INPROGRESS" ]

        do

             sleep 60s

             echo "Round $ROUND" >>$BACKUP_LOG

             ((ROUND++))

             curl -k --cookie $COOKIES \

               -H 'Accept:application/json' \

               --globoff -s \

               "https://$VC_ADDRESS/rest/appliance/recovery/backup/job/$ID" \

               >log/response-$VC_ADDRESS.txt

             cat log/response-$VC_ADDRESS.txt >>$BACKUP_LOG

             echo ''  >>$BACKUP_LOG

             PROGRESS=$(awk 'BEGIN{ FS=":" ; RS="," } $1 ~ "state" { print $2 }' log/response-$VC_ADDRESS.txt | sed "s/\"//g")

             echo 'Backup job state: '$PROGRESS >>$BACKUP_LOG

        done

         

         

        echo "Backup job completion status: $PROGRESS" >>$BACKUP_LOG

        echo ''  >>$BACKUP_LOG

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

          Oh yeah, maybe the directory was hardcoded, sorry for that :-)

           

          Can you have a look at your vCSA - login via ssh and show the output of the backup logfiles:

           

          root@vcenter [ /var/log/vmware/applmgmt ]# ls *backup*
          backup.log  backup.log.1.gz  backupRestoreProgress.log  backupSchedulerCron.log  backupScheduler.log

          I think you should fine your error in this logfiles.

           

          Regards,

          Alex

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

            Thanks Alex.

             

            So finally i managed to run the default scrip from vmware and it does copy the backup to FTP. Question is can this be scheduled. I created a cron job using below but could not find anything anywhere.  I hope this script can be scheduled..

             

            VMware vSphere 6.5 Documentation Library

             

            PS:_ i am a windows guy so my linux skills are questionable at best

             

            /usr/local/bin ]# crontab -e

            no crontab for root - using an empty one

            crontab: installing new crontab

             

            It opened up a VI editor and i simply pasted the path as below

             

            0 1 * * * /usr/local/bin/vCSA-Backup.sh

            Above will run daily at 1 AM local time but i am unable to see this in any where. I tried looking into cron.daily directory but no luck... just wondering where that went . Idea was to test the cron job...

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

              What was your problem with the script?

               

              Regarding your cron question, find my crontab here:

               

              vmware@vcsa-backup:~ > crontab -l | grep vmware 
              0 1 * * * /home/vmware/backup.sh vc-intern01
              0 2 * * * /home/vmware/backup.sh vc-extern01
              0 3 * * * /home/vmware/backup.sh vc-vdc01
              0 5 * * * /home/vmware/cleanup.sh
              

               

              Just change the directory paths and script names, then it should work

               

              For an idea if it works - have a look at the backup.log at the vCSA direct as mentioned above.

               

              Hope to help.

              Alex

              1 person found this helpful
              • 19. Re: schedule VCSA 6.5 backups..
                sushilkm Enthusiast

                Awesome .

                 

                / ]# crontab -l

                0 1 * * * /usr/local/bin/backup2.sh

                 

                Just hoping this will work as backup2,sh is a executable in itself. Not sure if i can trigger this job now or not  like windows scheduler.

                 

                As for script failing goes, can see few Curl errors like

                 

                stdOut:

                stdErr: curl: (21) QUOT command failed with 500

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

                  Thanks for your help guys. @daphnissov

                  aleex42

                  The default script provided by VMware have worked like a charm and managed to set & test the crobjob as well. Must add the community rocks.

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

                    No problem and enjoy your backups

                    1 2 Previous Next