From d554c478f20bc16e042be2be31b1c510f385c64d Mon Sep 17 00:00:00 2001 From: ssamson-tis Date: Wed, 25 Mar 2015 12:27:57 +0100 Subject: [PATCH] Bugfix: - vmdk imports - stats logs with rsync --- libtisbackup/backup_rsync.py | 13 +++++++------ libtisbackup/backup_vmdk.py | 30 +++++++++++++++++++----------- samples/tisbackup-config.ini | 6 ++++++ tisbackup.py | 1 + 4 files changed, 33 insertions(+), 17 deletions(-) mode change 100644 => 100755 tisbackup.py diff --git a/libtisbackup/backup_rsync.py b/libtisbackup/backup_rsync.py index 3a6df87..1c69a43 100644 --- a/libtisbackup/backup_rsync.py +++ b/libtisbackup/backup_rsync.py @@ -139,7 +139,7 @@ class backup_rsync(backup_generic): backup_source = '%s@%s::%s%s' % (self.remote_user, self.server_name, self.rsync_module, self.remote_dir) else: # case of rsync + ssh - ssh_params = ['-o StrictHostKeyChecking=no','-c blowfish'] + ssh_params = ['-o StrictHostKeyChecking=no','-c %s' % self.cipher_spec] if self.private_key: ssh_params.append('-i %s' % self.private_key) if self.ssh_port <> 22: @@ -168,13 +168,13 @@ class backup_rsync(backup_generic): for l in log.splitlines(): if l.startswith('Number of files:'): - stats['total_files_count'] += int(l.split(':')[1]) + stats['total_files_count'] += int(re.sub("[^0-9]", "", l.split(':')[1])) if l.startswith('Number of files transferred:'): - stats['written_files_count'] += int(l.split(':')[1]) + stats['written_files_count'] += int(re.sub("[^0-9]", "", l.split(':')[1])) if l.startswith('Total file size:'): - stats['total_bytes'] += int(l.split(':')[1].split()[0]) + stats['total_bytes'] += int(re.sub("[^0-9]", "", l.split(':')[1].split()[0])) if l.startswith('Total transferred file size:'): - stats['written_bytes'] += int(l.split(':')[1].split()[0]) + stats['written_bytes'] += int(re.sub("[^0-9]", "", l.split(':')[1].split()[0])) returncode = process.returncode ## deal with exit code 24 (file vanished) @@ -310,7 +310,8 @@ class backup_rsync_ssh(backup_rsync): """Backup a directory on remote server with rsync and ssh protocol (requires rsync software on remote host)""" type = 'rsync+ssh' required_params = backup_generic.required_params + ['remote_user','remote_dir','private_key'] - optional_params = backup_generic.optional_params + ['compression','bwlimit','ssh_port','exclude_list','protect_args','overload_args'] + optional_params = backup_generic.optional_params + ['compression','bwlimit','ssh_port','exclude_list','protect_args','overload_args', 'cipher_spec'] + cipher_spec = 'cipher_spec' register_driver(backup_rsync) diff --git a/libtisbackup/backup_vmdk.py b/libtisbackup/backup_vmdk.py index 04a010e..6719060 100755 --- a/libtisbackup/backup_vmdk.py +++ b/libtisbackup/backup_vmdk.py @@ -44,11 +44,12 @@ class backup_vmdk(backup_generic): type = 'esx-vmdk' required_params = backup_generic.required_params + ['esxhost','password_file','server_name'] - optional_params = backup_generic.optional_params + ['esx_port', 'prefix_clone', 'create_ovafile'] + optional_params = backup_generic.optional_params + ['esx_port', 'prefix_clone', 'create_ovafile', 'halt_vm'] esx_port = 443 prefix_clone = "clone-" create_ovafile = "no" + halt_vm = "no" def make_compatible_cookie(self,client_cookie): cookie_name = client_cookie.split("=", 1)[0] @@ -234,19 +235,26 @@ class backup_vmdk(backup_generic): vmList = vmFolder.childEntity for vm in vmList: if vm.name == self.server_name: - if not vm.summary.runtime.powerState == "poweredOff": + vm_is_off = vm.summary.runtime.powerState == "poweredOff" + if str2bool(self.halt_vm): + vm.ShutdownGuest() + vm_is_off = True + + if vm_is_off: + vmdks = self.export_vmdks(vm) + ovf_filename = self.create_ovf(vm, vmdks) + else: new_vm = self.clone_vm(vm) vmdks = self.export_vmdks(new_vm) ovf_filename = self.create_ovf(vm, vmdks) - if str2bool(self.create_ovafile): - ova_filename = self.create_ova(vm, vmdks, ovf_filename) - self.wait_task(new_vm.Destroy_Task()) - else: - vmdks = self.export_vmdks(vm) - ovf_filename = self.create_ovf(vm, vmdks) - if str2bool(self.create_ovafile): - ova_filename = self.create_ova(vm, vmdks, ovf_filename) - + self.wait_task(new_vm.Destroy_Task()) + + if str2bool(self.create_ovafile): + ova_filename = self.create_ova(vm, vmdks, ovf_filename) + + if str2bool(self.halt_vm): + vm.PowerOnVM() + if os.path.exists(dest_dir): for file in os.listdir(dest_dir): diff --git a/samples/tisbackup-config.ini b/samples/tisbackup-config.ini index d52bba3..88e911c 100644 --- a/samples/tisbackup-config.ini +++ b/samples/tisbackup-config.ini @@ -91,3 +91,9 @@ db_user=sa db_password=xxx +[debian-ovf] +type=esx-vmdk +server_name=debian +esxhost=192.168.149.213 +password_file=/etc/.esx_passwd +create_ovafile=yes diff --git a/tisbackup.py b/tisbackup.py old mode 100644 new mode 100755 index eeae082..f192bbb --- a/tisbackup.py +++ b/tisbackup.py @@ -36,6 +36,7 @@ from libtisbackup.backup_rsync_btrfs import backup_rsync_btrfs from libtisbackup.backup_rsync_btrfs import backup_rsync__btrfs_ssh from libtisbackup.backup_pgsql import backup_pgsql from libtisbackup.backup_xva import backup_xva +from libtisbackup.backup_vmdk import backup_vmdk #from libtisbackup.backup_switch import backup_switch from libtisbackup.backup_null import backup_null from libtisbackup.backup_xcp_metadata import backup_xcp_metadata