def backup(args): if args.repos: provider = get_provider_from_config(args.config) today = datetime.datetime.now().date() abs_date_dir = get_abs_date_dir(args.archive_dir, today) mkdir_p(args.staging_dir) mkdir_p(args.archive_dir) mkdir_p(abs_date_dir) repo_objs = get_repo_objs_from_provider(provider, args.repos) if repo_objs: for repo in repo_objs: repo_dir_to_create = os.path.join(args.staging_dir, repo.name) bundle_dir_to_create = os.path.join(abs_date_dir, repo.name) mkdir_p(repo_dir_to_create) mkdir_p(bundle_dir_to_create) bundle_file_to_create = os.path.join( bundle_dir_to_create, "{}.bundle".format(repo.name)) subprocess.check_call( ["git", "clone", "--no-hardlinks", "--mirror", repo.clone_url, repo_dir_to_create]) os.chdir(repo_dir_to_create) subprocess.check_call( ["git", "bundle", "create", bundle_file_to_create, "--all"]) create_tarball([bundle_dir_to_create], repo.name, abs_date_dir) # cleanup rm_rf(bundle_dir_to_create) else: logging.error("Please provide repos to backup.")
def backup(args): if args.repos: provider = get_provider_from_config(args.config) today = datetime.datetime.now().date() abs_date_dir = get_abs_date_dir(args.archive_dir, today) mkdir_p(args.staging_dir) mkdir_p(args.archive_dir) mkdir_p(abs_date_dir) repo_objs = get_repo_objs_from_provider(provider, args.repos) if repo_objs: for repo in repo_objs: repo_dir_to_create = os.path.join(args.staging_dir, repo.name) bundle_dir_to_create = os.path.join(abs_date_dir, repo.name) mkdir_p(repo_dir_to_create) mkdir_p(bundle_dir_to_create) bundle_file_to_create = os.path.join( bundle_dir_to_create, "{}.bundle".format(repo.name)) subprocess.check_call([ "git", "clone", "--no-hardlinks", "--mirror", repo.clone_url, repo_dir_to_create ]) os.chdir(repo_dir_to_create) subprocess.check_call([ "git", "bundle", "create", bundle_file_to_create, "--all" ]) create_tarball([bundle_dir_to_create], repo.name, abs_date_dir) # cleanup rm_rf(bundle_dir_to_create) else: logging.error("Please provide repos to backup.")
def test_get_abs_date_dir(self): date = datetime.date(2012, 1, 11) tmp_ensure_date_dir = os.path.join(self.temp_dir, 'ensure_date') abs_date_dir = get_abs_date_dir(tmp_ensure_date_dir, date) ok_('ensure_date/2012/01/11' in abs_date_dir)