mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-06 00:28:01 +01:00
Merge pull request #54 from amaczuga/master
Support archivization using bare git clones
This commit is contained in:
10
README.rst
10
README.rst
@@ -29,10 +29,11 @@ CLI Usage is as follows::
|
|||||||
[-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched]
|
[-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched]
|
||||||
[--all] [--issues] [--issue-comments] [--issue-events]
|
[--all] [--issues] [--issue-comments] [--issue-events]
|
||||||
[--pulls] [--pull-comments] [--pull-commits] [--labels]
|
[--pulls] [--pull-comments] [--pull-commits] [--labels]
|
||||||
[--hooks] [--milestones] [--repositories] [--wikis]
|
[--hooks] [--milestones] [--repositories] [--bare]
|
||||||
[--skip-existing] [-L [LANGUAGES [LANGUAGES ...]]]
|
[--wikis] [--skip-existing]
|
||||||
[-N NAME_REGEX] [-H GITHUB_HOST] [-O] [-R REPOSITORY]
|
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
|
||||||
[-P] [-F] [--prefer-ssh] [-v]
|
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
|
||||||
|
[--prefer-ssh] [-v]
|
||||||
USER
|
USER
|
||||||
|
|
||||||
Backup a github account
|
Backup a github account
|
||||||
@@ -66,6 +67,7 @@ CLI Usage is as follows::
|
|||||||
authenticated)
|
authenticated)
|
||||||
--milestones include milestones in backup
|
--milestones include milestones in backup
|
||||||
--repositories include repository clone in backup
|
--repositories include repository clone in backup
|
||||||
|
--bare clone bare repositories
|
||||||
--wikis include wiki clone in backup
|
--wikis include wiki clone in backup
|
||||||
--skip-existing skip project if a backup directory exists
|
--skip-existing skip project if a backup directory exists
|
||||||
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]
|
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]
|
||||||
|
|||||||
@@ -204,6 +204,10 @@ def parse_args():
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
dest='include_repository',
|
dest='include_repository',
|
||||||
help='include repository clone in backup')
|
help='include repository clone in backup')
|
||||||
|
parser.add_argument('--bare',
|
||||||
|
action='store_true',
|
||||||
|
dest='bare_clone',
|
||||||
|
help='clone bare repositories')
|
||||||
parser.add_argument('--wikis',
|
parser.add_argument('--wikis',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='include_wiki',
|
dest='include_wiki',
|
||||||
@@ -508,14 +512,16 @@ def backup_repositories(args, output_directory, repositories):
|
|||||||
fetch_repository(repository['name'],
|
fetch_repository(repository['name'],
|
||||||
repo_url,
|
repo_url,
|
||||||
repo_dir,
|
repo_dir,
|
||||||
skip_existing=args.skip_existing)
|
skip_existing=args.skip_existing,
|
||||||
|
bare_clone=args.bare_clone)
|
||||||
|
|
||||||
download_wiki = (args.include_wiki or args.include_everything)
|
download_wiki = (args.include_wiki or args.include_everything)
|
||||||
if repository['has_wiki'] and download_wiki:
|
if repository['has_wiki'] and download_wiki:
|
||||||
fetch_repository(repository['name'],
|
fetch_repository(repository['name'],
|
||||||
repo_url.replace('.git', '.wiki.git'),
|
repo_url.replace('.git', '.wiki.git'),
|
||||||
os.path.join(repo_cwd, 'wiki'),
|
os.path.join(repo_cwd, 'wiki'),
|
||||||
skip_existing=args.skip_existing)
|
skip_existing=args.skip_existing,
|
||||||
|
bare_clone=args.bare_clone)
|
||||||
|
|
||||||
if args.include_issues or args.include_everything:
|
if args.include_issues or args.include_everything:
|
||||||
backup_issues(args, repo_cwd, repository, repos_template)
|
backup_issues(args, repo_cwd, repository, repos_template)
|
||||||
@@ -695,7 +701,7 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
|
|||||||
log_info("Unable to read hooks, skipping")
|
log_info("Unable to read hooks, skipping")
|
||||||
|
|
||||||
|
|
||||||
def fetch_repository(name, remote_url, local_dir, skip_existing=False):
|
def fetch_repository(name, remote_url, local_dir, skip_existing=False, bare_clone=False):
|
||||||
clone_exists = os.path.exists(os.path.join(local_dir, '.git'))
|
clone_exists = os.path.exists(os.path.join(local_dir, '.git'))
|
||||||
|
|
||||||
if clone_exists and skip_existing:
|
if clone_exists and skip_existing:
|
||||||
@@ -723,6 +729,9 @@ def fetch_repository(name, remote_url, local_dir, skip_existing=False):
|
|||||||
log_info('Cloning {0} repository from {1} to {2}'.format(name,
|
log_info('Cloning {0} repository from {1} to {2}'.format(name,
|
||||||
masked_remote_url,
|
masked_remote_url,
|
||||||
local_dir))
|
local_dir))
|
||||||
|
if bare_clone:
|
||||||
|
git_command = ['git', 'clone', '--bare', remote_url, local_dir]
|
||||||
|
else:
|
||||||
git_command = ['git', 'clone', remote_url, local_dir]
|
git_command = ['git', 'clone', remote_url, local_dir]
|
||||||
logging_subprocess(git_command, None)
|
logging_subprocess(git_command, None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user