def test_dir_full_pipeline(self): """Basic test of a single directory archive, encrypt and backup.""" try: # Setup the test state. tempdir, in_dir, out_dir = self._create_tempdir_structure('input', \ 'output') in_struct, out_struct, cfg_file = self._create_single_dir_test(\ 'struct', 'struct.tar.xz.gpg', tempdir, in_dir, tempdir, \ [_ConfigSection('input/struct', tempdir, archive='yes', compress='yes', encrypt='yes')]) in_dir_hash = test.get_dir_md5(in_dir) # Run backup. with redir_stdstreams() as (stdout, stderr): backup.main(['--config', cfg_file, '--gpg-home', test.GPG_HOME]) self.assertEqual('', stdout.getvalue().strip()) self.assertEqual('', stderr.getvalue().strip()) # Assert the output state looks as we expect. self.assertTrue(os.path.isdir(in_struct)) self.assertTrue(os.path.isfile(out_struct)) self.assertEqual(in_dir_hash, test.get_dir_md5(in_dir)) undo_out_file = os.path.join(out_dir, 'struct') backup.unencrypt_path(os.path.join(tempdir, 'struct.tar.xz'), out_struct, homedir=test.GPG_HOME) backup.uncompress_path(os.path.join(tempdir, 'struct.tar'), os.path.join(tempdir, 'struct.tar.xz')) backup.unarchive_path(out_dir, os.path.join(tempdir, 'struct.tar')) self.assertTrue(os.path.isdir(undo_out_file)) self.assertEqual(in_dir_hash, test.get_dir_md5(out_dir)) finally: shutil.rmtree(tempdir)
def test_dir(self): """Most basic test of a single directory backup.""" try: # Setup the test state. tempdir, in_dir, out_dir = self._create_tempdir_structure('input', \ 'output') in_struct, out_struct, cfg_file = self._create_single_dir_test(\ 'struct', 'struct', tempdir, in_dir, out_dir, \ [_ConfigSection('input/struct', out_dir)]) in_dir_hash = test.get_dir_md5(in_dir) # Run backup. with redir_stdstreams() as (stdout, stderr): backup.main(['--config', cfg_file]) self.assertEqual('', stdout.getvalue().strip()) self.assertEqual('', stderr.getvalue().strip()) # Assert the output state looks as we expect. self.assertTrue(os.path.isdir(in_struct)) self.assertTrue(os.path.isdir(out_struct)) self.assertEqual(in_dir_hash, test.get_dir_md5(in_dir)) self.assertEqual(in_dir_hash, test.get_dir_md5(out_dir)) finally: shutil.rmtree(tempdir)
def test_file_encrypt(self): """Basic test of a single file encrypt and backup.""" try: # Setup the test state. tempdir, in_dir, out_dir = self._create_tempdir_structure('input', \ 'output') in_file, out_file, cfg_file = self._create_single_file_test(\ 'file.txt', 'file.txt.gpg', tempdir, in_dir, out_dir, \ [_ConfigSection('input/file.txt', out_dir, encrypt='yes')]) in_dir_hash = test.get_dir_md5(in_dir) in_file_hash = test.get_file_md5(in_file) # Run backup. with redir_stdstreams() as (stdout, stderr): backup.main(['--config', cfg_file, '--gpg-home', test.GPG_HOME]) self.assertEqual('', stdout.getvalue().strip()) self.assertEqual('', stderr.getvalue().strip()) # Assert the output state looks as we expect. self.assertTrue(os.path.isfile(in_file)) self.assertTrue(os.path.isfile(out_file)) self.assertEqual(in_dir_hash, test.get_dir_md5(in_dir)) undo_out_file = os.path.join(tempdir, 'file.txt') backup.unencrypt_path(undo_out_file, out_file, homedir=test.GPG_HOME) self.assertTrue(os.path.isfile(undo_out_file)) self.assertEqual(in_file_hash, test.get_file_md5(undo_out_file)) finally: shutil.rmtree(tempdir)
def test_file_tree(self): date = backup.main() shows = pickle_load('data/test_shows.pkl') save_shows(shows) tree = file_tree.main() restore_backup.main(date=date) recursive_delete(os.path.join(BACKUP_DIR, date))
def main(args): parse_args(args) unlock() config = load_json(environ[CONF_FILE]) start = time() print('running', SERIES_DIR) if not backup.main(): print('backup failed') exit(-2) else: print('backup successful') load_shows(reload=True) shows = load_files(SERIES_DIR) shows.update(load_files(ANIME_DIR)) if config['reload_metadata']: shows = reload_metadata(shows) else: add_metadata(shows) save_shows(shows) print(time() - start) return shows
def update_inputrc(): if os.path.isfile('{}/.inputrc'.format(USER)): print("\nReplacing existing ~/.inputrc") else: print("\nCreating ~/.inputrc") shutil.copy2('{}/inputrc_config'.format(ROOT_DIR), '{}/.inputrc'.format(USER)) def update_bash_bindings(): if os.path.isfile('{}/.bash_bindings'.format(USER)): print("\nReplacing existing ~/.bash_bindings") else: print("\nCreating ~/.bash_bindings") shutil.copy2('{}/bash_bindings_config'.format(ROOT_DIR), '{}/.bash_bindings'.format(USER)) if __name__ == '__main__': print("Creating a backup in case anything goes wrong.\n") backup.main() append_bashrc() update_inputrc() update_bash_bindings() print("\nSetup complete. Restart terminal to make changes take effect.")
def get_similar_data(input_query, country_name): backup.main(input_query, country_name)
'--config-file', dest='config_file', default="E:\\Huyen Trang\\project\\djangows\\client\\windows\\client.conf", help='Path of config file') parser.add_argument('-t', dest='repo_targets', required=True, nargs='*', help='Path of directory need to backup') parser.add_argument('-s', dest='server_address', help='Server backup') parser.add_argument('-j', dest='job_id', help='Job in controller') args = parser.parse_args() print(args) if os.path.exists(args.config_file): pass else: print("File config does not exist ") exit(1) for repo_target in args.repo_targets: if os.path.exists(repo_target): if repo_target.endswith('\\'): repo_target = repo_target[:len(repo_target) - 1] main(args, repo_target) else: err = "Specified path does not exist" main(args, repo_target, err) print(err)
try: a=config.read(args.filename) for database in config.get("DEFAULT", "db_name").split("\n"): print("Using db: "+database) if(config["DEFAULT"]["backup_db_type"]=="postgresql"): if(config["DEFAULT"]["remote_db"]=="yes"): import remote exit_value=remote.main(config,database) if(config["DEFAULT"]["backup_remotely"]=="yes"): import from_remote_to_local exit_value=from_remote_to_local.main(config,database) else: import backup exit_value=backup.main(config,database) ##postgresql else: if(config["DEFAULT"]["remote_db"]=="yes"): import remote_mysql exit_value=remote_mysql.main(config,database) else: import mysql exit_value=mysql.main(config,database) if(exit_value!=0): print("Internal ERROR: Exit value was !=0") except configparser.NoOptionError: sys.stderr.write("Erorr: Invalid/no option found for a row in config file")