def test_nolinks_linkname(self): ''' Test that after running a nolinks backup, the 'current' link points to a full backup, not the partial one. ''' print('') print('Running test nolinks_linkname.') # Set backup type to incremental config = self._get_testing_config() config['testing']['backup_type'] = 'incremental' self._write_config_file(config) # Run backups with the relevant command line arguments ink.main(self.argv) # Get the directory containing the most recent backups first_backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Set backup type to nolinks config['testing']['backup_type'] = 'nolinks' self._write_config_file(config) # Sleep for 1 second to make sure backups run again time.sleep(1) # Run backups again ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name))
def test_snapshot_update_backup(self): ''' Test that a snapshot backup updates itself. ''' print('') print('Running test snapshot_update_backup.') # Set backup type to snapshot config = self._get_testing_config() config['testing']['backup_type'] = 'snapshot' self._write_config_file(config) # Make backups of original files ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = self.backups_container_dirname # Get the modification times of the files modification_times = [] for filecfg in self.files: modification_times.append( os.path.getmtime(os.path.join(backup_dirname, filecfg['name']))) # Update one file updated_files = copy.deepcopy(self.files) updated_files[0]['contents'] += ' Updated.' self._create_original_files(updated_files) # Sleep for one second to make sure new backups will be run time.sleep(1) # Run backups again ink.main(self.argv) # Loop through newest backup folder and expect the content to be # updated. self._compare_directory_content(updated_files, backup_dirname) # Expect the first file to have a new, later modification time but the # others to be the same for index, filecfg in enumerate(updated_files): if index == 0: self.assertGreater( os.path.getmtime( os.path.join(backup_dirname, filecfg['name'])), modification_times[index]) else: self.assertEqual( os.path.getmtime( os.path.join(backup_dirname, filecfg['name'])), modification_times[index])
def test_full_update_backup(self): ''' Test that a full backup updates itself. ''' print('') print('Running test full_update_backup.') # Set backup type to full config = self._get_testing_config() config['testing']['backup_type'] = 'full' self._write_config_file(config) # Make backups of original files ink.main(self.argv) # Get the directory containing the first backups first_backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Update one file updated_files = copy.deepcopy(self.files) updated_files[0]['contents'] += ' Updated.' self._create_original_files(updated_files) # Sleep for one second to make sure new backups will be run time.sleep(1) # Run backups again ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Loop through newest backup folder and expect the content to be # updated. self._compare_directory_content(updated_files, backup_dirname) # Loop through the first backup folder and expect the content to be the # original self._compare_directory_content(self.files, first_backup_dirname) # Expect none of the files to be hardlinks for filecfg in updated_files[1:]: self.assertFalse(self._is_hard_link( os.path.join(first_backup_dirname, filecfg['name']), os.path.join(backup_dirname, filecfg['name'])))
def test_nolinks_update_backup(self): ''' Test that an incremental backup updates itself. ''' print('') print('Running test nolinks_update_backup.') # Set backup type to nolinks config = self._get_testing_config() config['testing']['backup_type'] = 'nolinks' self._write_config_file(config) # Make backups of original files ink.main(self.argv) # Get the directory containing the first backups first_backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Update one file updated_files = copy.deepcopy(self.files) updated_files[0]['contents'] += ' Updated.' self._create_original_files(updated_files) # Sleep for one second to make sure new backups will be run time.sleep(1) # Run backups again ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # The first directory now has a suffix of _bak first_backup_dirname += '_bak' # Loop through newest backup folder and expect the content to be # updated. self._compare_directory_content(updated_files, backup_dirname) # Expect the first backup directory to contain the first file self._compare_directory_content([self.files[0]], first_backup_dirname) # Expect all other files to not exist in first backup directory for filecfg in self.files[1:]: self.assertFalse(os.path.isfile(os.path.join(first_backup_dirname, filecfg['name'])))
def test_make_incremental_backup(self): ''' Test that a simple backup can be made.''' print('') print('Running test make_incremental_backup.') # Set backup type to incremental config = self._get_testing_config() config['testing']['backup_type'] = 'incremental' self._write_config_file(config) # Run backups with the relevant command line arguments ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Check that all files in original directory exist in backup directory # and have identical contents self._compare_directory_content(self.files, backup_dirname)
def test_make_snapshot_backup(self): ''' Test that a simple snapshot backup can be made.''' print('') print('Running test make_snapshot_backup.') # Set backup type to snapshot config = self._get_testing_config() config['testing']['backup_type'] = 'snapshot' self._write_config_file(config) # Run backups with the relevant command line arguments ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = self.backups_container_dirname # Check that all files in original directory exist in backup directory # and have identical contents for filecfg in self.files: with open(os.path.join(backup_dirname, filecfg['name']), 'r') \ as testfile: self.assertEqual(testfile.read(), filecfg['contents'])
def test_default_exclude(self): ''' Test that the folder containing the backups is excluded when it is a child of the directory being backed up. ''' print('') print('Running test default_exclude.') # Set backup type to incremental config = self._get_testing_config() config['testing']['backup_type'] = 'incremental' # Backup the root directory config['testing']['to_backup'] = self.root_dir.name self._write_config_file(config) # Run backups with the relevant command line arguments ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Check that the folder containing the backups does not exist in the # backup path_to_check = os.path.join( backup_dirname, os.path.relpath( self.backups_container_dirname, self.root_dir.name) ) self.assertFalse(os.path.exists(path_to_check)) # Check that all other files do self._compare_directory_content( self.files, os.path.join( backup_dirname, os.path.relpath(self.orig_dirname,self.root_dir.name) ) )
def test_rebase_root(self): ''' Test that the rebase_root option works.''' print('') print('Running test rebase_root.') # Set backup type to incremental config = self._get_testing_config() config['testing']['backup_type'] = 'incremental' # Set rebase_root option config['testing']['rebase_root'] = 'true' self._write_config_file(config) # Run backups with the relevant command line arguments ink.main(self.argv) # Get the directory containing the most recent backups backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name, self.orig_dirname[1:])) # Check that all files in original directory exist in backup directory # and have identical contents self._compare_directory_content(self.files, backup_dirname)
def test_frequency(self): ''' Test that the frequency option works.''' print('') print('Running test frequency.') # Set backup type to incremental config = self._get_testing_config() config['testing']['backup_type'] = 'incremental' # Set backup frequency frequency = 5 config['testing']['frequency_seconds'] = '5' #'{:d}'.format(frequency) self._write_config_file(config) # Run backups with the relevant command line arguments first_backup_time = time.time() ink.main(self.argv) # Get the directory containing the most recent backups first_backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) # Check that the time elapsed is less than the frequency and try making # backups again self.assertLess( time.time(), first_backup_time + frequency, msg='Frequency is too short. Increase the frequency and ' 'run the test again.') ink.main(self.argv) # No new backup should be created backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) self.assertEqual(backup_dirname, first_backup_dirname) # Wait until time elapsed is greater than frequency and try making # backups again time.sleep(frequency) self.assertGreater(time.time(), first_backup_time + frequency) ink.main(self.argv) # New backups should be created backup_dirname = os.path.realpath( os.path.join(self.backups_container_dirname, self.link_name)) self.assertNotEqual(backup_dirname, first_backup_dirname)