def test_backup_swift_mysql(self): self.source_tree = common.Temp_Tree(dir='/var/lib/mysql', create=False) backup_name = uuidutils.generate_uuid(dashed=False) lvm_snapsize = '1G' lvm_snapname = 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) backup_args = { 'action': 'backup', 'mode': 'mysql', 'mysql_conf': '/etc/mysql/debian.cnf', 'path_to_backup': self.source_tree.path, 'snapshot': '', 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': 'freezer_test_container_{0}'.format(backup_name), 'storage': 'swift', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']) } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result)
def test_backup_os_simple_with_bandwidth_limit(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'max_level': '6', 'upload_limit': '1M', 'download_limit': '1M', 'max_segment_size': '67108864', 'backup_name': uuidutils.generate_uuid(dashed=False), 'storage': 'swift', 'container': 'freezer_test_backups_{0}'.format( uuidutils.generate_uuid(dashed=False)), 'metadata_out': '-' } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } remove_args = { 'action': 'admin', 'remove_older_than': 0, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } # --- backup result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = json.loads(result) self.assertIn('backup_name', result) self.assertEqual(result['backup_name'], backup_args['backup_name']) self.assertIn('container', result) self.assertEqual(result['container'], backup_args['container']) # It may be reasonable to insert a check of the files in the # swift container # file_list = self.get_file_list_openstack(result['container']) # --- restore result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() # --- remove backups and container result = common.execute_freezerc(remove_args) self.assertIsNotNone(result) result = self.remove_swift_container(backup_args['container']) self.assertIsNotNone(result)
def test_backup_os_simple_with_bandwidth_limit(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'max_level': '6', 'upload_limit': '1M', 'download_limit': '1M', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex, 'storage': 'swift', 'container': 'freezer_test_backups_{0}'.format(uuid.uuid4().hex), 'metadata_out': '-' } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } remove_args = { 'action': 'admin', 'remove_older_than': 0, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } # --- backup result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = json.loads(result) self.assertIn('backup_name', result) self.assertEqual(result['backup_name'], backup_args['backup_name']) self.assertIn('container', result) self.assertEqual(result['container'], backup_args['container']) # It may be reasonable to insert a check of the files in the # swift container # file_list = self.get_file_list_openstack(result['container']) # --- restore result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() # --- remove backups and container result = common.execute_freezerc(remove_args) self.assertIsNotNone(result) result = self.remove_swift_container(backup_args['container']) self.assertIsNotNone(result)
def test_backup_multiple_level(self): """How it works? - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add some random data - check that trees don't match anymore - execute block based backup of source tree - modify data - execute backup again - delete some files - execute backup again - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuidutils.generate_uuid(dashed=False) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'engine': 'rsync', 'max_segment_size': '67108864', 'backup_name': backup_name, } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': backup_name, 'storage': 'local', 'engine': 'rsync', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) self.source_tree.modify_random_files(2) result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) self.source_tree.delete_random_files(1) result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_multiple_level(self): """How it works? - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add some random data - check that trees don't match anymore - execute block based backup of source tree - modify data - execute backup again - delete some files - execute backup again - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuid.uuid4().hex with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'engine': 'rsync', 'max_segment_size': '67108864', 'backup_name': backup_name, } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': backup_name, 'storage': 'local', 'engine': 'rsync', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) self.source_tree.modify_random_files(2) result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) self.source_tree.delete_random_files(1) result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_ssh_incremental(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuidutils.generate_uuid(dashed=False), 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host, 'metadata_out': '-' } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = json.loads(result) sub_path = '_'.join([result['hostname'], result['backup_name']]) # It may be reasonable to insert a check of the files in the # storage directory # file_list = self.get_file_list_ssh(sub_path) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() # -- many levels self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.do_backup_and_restore_with_check(backup_args, restore_args) self.remove_ssh_directory(sub_path)
def test_backup_single_file(self): """ - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add one file with random data - check that trees don't match anymore - execute block based backup of single file - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data(ndir=0, nfile=1) self.assertTreesMatchNot() with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': os.path.join(self.source_tree.path, self.source_tree.files[0]), 'container': storage_dir.path, 'storage': 'local', 'engine': 'rsync', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'engine': 'rsync', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_local_storage_lvm_raises_path_mismatch(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuid.uuid4().hex lvm_auto_snap= self.source_tree.path lvm_snapsize= '1G' lvm_snapname= 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': path_to_backup, 'lvm_auto_snap': lvm_auto_snap, 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } result = common.execute_freezerc( backup_args, must_fail=True, merge_stderr=True) self.assertIn('Path to backup mismatch', result)
def test_backup_single_file(self): """ - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add one file with random data - check that trees don't match anymore - execute block based backup of single file - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data(ndir=0, nfile=1) self.assertTreesMatchNot() with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': os.path.join( self.source_tree.path, self.source_tree.files[0]), 'container': storage_dir.path, 'storage': 'local', 'engine': 'rsync', 'max_segment_size': '67108864', 'backup_name': uuidutils.generate_uuid(dashed=False) } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'engine': 'rsync', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_single_level(self): """How it works? - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add some random data - check that trees don't match anymore - execute block based backup of source tree - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data() self.assertTreesMatchNot() with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'engine': 'rsync', 'max_segment_size': '67108864', 'backup_name': uuidutils.generate_uuid(dashed=False) } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'engine': 'rsync', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_single_level(self): """ - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add some random data - check that trees don't match anymore - execute backup of source tree - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data() self.assertTreesMatchNot() with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() self.do_backup_and_restore_with_check(backup_args, restore_args)
def test_backup_local_storage_use_lvm_snapshot_and_path_to_backup(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuid.uuid4().hex lvm_auto_snap= self.source_tree.path lvm_snapsize= '50M' lvm_snapname= 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': lvm_auto_snap, 'snapshot': '', 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_ssh_incremental_with_lvm(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuidutils.generate_uuid(dashed=False) path_to_backup = self.source_tree.path lvm_snapsize = '1G' lvm_snapname = 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': path_to_backup, 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'backup_name': backup_name, 'max_level': '6', 'max_segment_size': '67108864', 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() # -- level 1 self.source_tree.add_random_data() self.assertTreesMatchNot() result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch() # -- level 2 self.source_tree.add_random_data() self.assertTreesMatchNot() result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_local_storage_use_lvm_snapshot_and_path_to_backup(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuidutils.generate_uuid(dashed=False) path_to_backup = self.source_tree.path lvm_snapsize = '50M' lvm_snapname = 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': path_to_backup, 'snapshot': '', 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_backup_preexisting_dir(self): """ Use external pre-defined directory for tests. If directory does not exist, then skip Restore to temporary folder (removed on exit) :return: """ workdir = os.path.expanduser('~/test_dir') if not os.path.isdir(workdir): return self.source_tree = common.Temp_Tree(dir='/work', create=False) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuidutils.generate_uuid(dashed=False) } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute_freezerc(backup_args) self.assertIsNotNone(result) result = common.execute_freezerc(restore_args) self.assertIsNotNone(result) self.assertTreesMatch()
def test_freezerc_fails_with_wrong_params(self): result = common.execute_freezerc({'blabla': ''}, must_fail=True, merge_stderr=True) self.assertIn('unrecognized arguments', result)
def test_freezerc_executes(self): result = common.execute_freezerc({'version': ''}) self.assertIsNotNone(result)