wefixit-AT / oVirtBackup

This is a tool, written in Python, to make online fullbackup's of a VM which runs in an oVirt environment.
MIT License
105 stars 54 forks source link

Please test branch 4.3 with oVirt 4.4 #66

Open wefixit-AT opened 3 years ago

wefixit-AT commented 3 years ago

Can somebody please test branch 4.3 with oVirt 4.4 so I can merge the changes to the master branch, to have an up to date master branch.

Ziehnert commented 3 years ago

We are currently using it on oVirt 4.4, I also made some changes to work with python3. The only problem occurring right now is that the cloned VMs aren't automatically deleted after a backup. Probably since the sdk got updated, im already looking for the sdk changes.

hobyhop commented 3 years ago

No code updates for 4.4? I could start some tests in the next weeks (in a RHV production environment). Do I need updated information?

zroupas commented 2 years ago

Hi, i've been using this awesome script for months now with 4.2.3 without any problems. Now after moving to 4.4 and some python3, config tweaking i was able to run the backup/export successfully.

As @Ziehnert pointed out though , the only problem is that the cloned VM's aren't deleted and it seems that the script doesn't even try to remove those as it did in the previous version, for example in previous versions you could see in the log file entries like 2021-12-27 05:34:43,218: Delete cloned VM (test-vm__20211227_040755) started ...

@Ziehnert did you manage to find a solution?

Thanks

mrt85 commented 1 year ago

I replaced part of the code in vmtools.py 4.3 and the old VM's started to be deleted in 4.4

Replaced it

#    @staticmethod
#    def delete_vm(api, config, vm_name):
#        """
#        Delets a vm which was created during backup
#        :param vm: Virtual machine object
#        :param config: Configuration
#        """
#        done = False
#        try:
#            vms_service = api.system_service().vms_service()
#            vm_search_regexp = 'name=' + str(vm_name) + config.get_vm_middle() + '__*'
#            for vm in vms_service.list(search=vm_search_regexp):
#                logger.info("Delete cloned VM (%s) started ..." % vm.name)
#                if not config.get_dry_run():
#                    vm_service = vms_service.vm_service(vm.id)
#                    if vm_service is None:
#                        logger.warn(
#                            "The VM (%s) doesn't exist anymore, "
#                            "skipping deletion ...", vm.name
#                        )
#                        done = True
#                        continue
#                    vm.delete_protected = False
#                    vm_service.update(vm)
#                    while True:
#                        try:
#                            vm_service.remove()
#                            break
#                        except:
#                            logger.debug("Wait for previous clone operation to complete (VM %s status is %s)..." , vm.name, vm.status)
#                            time.sleep(config.get_timeout())
#                    while True:
#                        try:
#                            vm_service.get()
#                        except:
#                            break
#                        logger.debug("Deletion of cloned VM (%s) in progress ..." % vm.name)
#                        time.sleep(config.get_timeout())
#                    done = True
#        except Exception as e:
#            logger.info("!!! Can't delete cloned VM (%s)", vm.name)
#            raise e
#        if done:
#            logger.info("Cloned VM (%s) deleted" , vm.name)

with this

    @staticmethod
    def delete_vm(api, config, vm_name):
        """
        Delets a vm which was created during backup
        :param api: ovirtsdk api
        :param config: Configuration
        :param vm_name: Virtual machine object
        """
        global global_vm
        done = False
        try:
            vms_service = api.system_service().vms_service()
            vm_search_regexp = ("name=%s%s_*" % (vm_name, config.get_vm_middle()))
            for global_vm in vms_service.list(search=vm_search_regexp):
                logger.info("Delete cloned VM (%s) started ..." % global_vm.name)
                if not config.get_dry_run():
                    vm_service = vms_service.vm_service(global_vm.id)
                    if vm_service is None:
                        logger.warning(
                            "The VM (%s) doesn't exist anymore, "
                            "skipping deletion ...", global_vm.name
                        )
                        done = True
                        continue
                    global_vm.delete_protected = False
                    vm_service.update(global_vm)
                    while True:
                        try:
                            vm_service.remove()
                            break
                        except:
                            logger.debug("Wait for previous clone operation to complete (VM %s status is %s)...",
                                         global_vm.name, global_vm.status)
                            time.sleep(config.get_timeout())
                    while True:
                        try:
                            vm_service.get()
                        except:
                            break
                        logger.debug("Deletion of cloned VM (%s) in progress ..." % global_vm.name)
                        time.sleep(config.get_timeout())
                    done = True
        except Exception as e:
            logger.info("!!! Can't delete cloned VM (%s)", global_vm.name)
            raise e
        if done:
            logger.info("Cloned VM (%s) deleted", global_vm.name)