From e6b6eb8bef2117972c90ae29a9182d55f094c2a4 Mon Sep 17 00:00:00 2001 From: pieterclaerhout Date: Tue, 10 Oct 2017 19:52:07 +0200 Subject: [PATCH 1/3] Added support for LFS clones --- README.rst | 3 ++- bin/github-backup | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 7126cee..7b914c3 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ CLI Usage is as follows:: [-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched] [--all] [--issues] [--issue-comments] [--issue-events] [--pulls] [--pull-comments] [--pull-commits] [--labels] - [--hooks] [--milestones] [--repositories] [--bare] + [--hooks] [--milestones] [--repositories] [--bare] [--lfs] [--wikis] [--skip-existing] [-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX] [-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F] @@ -72,6 +72,7 @@ CLI Usage is as follows:: --milestones include milestones in backup --repositories include repository clone in backup --bare clone bare repositories + --lfs clone LFS repositories --wikis include wiki clone in backup --skip-existing skip project if a backup directory exists -L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]] diff --git a/bin/github-backup b/bin/github-backup index 30390a6..e1d8d80 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -208,6 +208,10 @@ def parse_args(): action='store_true', dest='bare_clone', help='clone bare repositories') + parser.add_argument('--lfs', + action='store_true', + dest='lfs_clone', + help='clone lfs repositories') parser.add_argument('--wikis', action='store_true', dest='include_wiki', @@ -540,7 +544,8 @@ def backup_repositories(args, output_directory, repositories): repo_url, repo_dir, skip_existing=args.skip_existing, - bare_clone=args.bare_clone) + bare_clone=args.bare_clone, + lfs_clone=arg.lfs_clone) download_wiki = (args.include_wiki or args.include_everything) if repository['has_wiki'] and download_wiki: @@ -548,7 +553,8 @@ def backup_repositories(args, output_directory, repositories): repo_url.replace('.git', '.wiki.git'), os.path.join(repo_cwd, 'wiki'), skip_existing=args.skip_existing, - bare_clone=args.bare_clone) + bare_clone=args.bare_clone, + lfs_clone=arg.lfs_clone) if args.include_issues or args.include_everything: backup_issues(args, repo_cwd, repository, repos_template) @@ -738,7 +744,8 @@ def fetch_repository(name, remote_url, local_dir, skip_existing=False, - bare_clone=False): + bare_clone=False, + lfs_clone=False): if bare_clone: if os.path.exists(local_dir): clone_exists = subprocess.check_output(['git', @@ -780,7 +787,10 @@ def fetch_repository(name, git_command = ['git', 'remote', 'set-url', 'origin', remote_url] logging_subprocess(git_command, None, cwd=local_dir) - git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune'] + if lfs_clone: + git_command = ['git', 'lfs', 'fetch', '--all', '--force', '--tags', '--prune'] + else: + git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune'] logging_subprocess(git_command, None, cwd=local_dir) else: log_info('Cloning {0} repository from {1} to {2}'.format( @@ -788,9 +798,15 @@ def fetch_repository(name, masked_remote_url, local_dir)) if bare_clone: - git_command = ['git', 'clone', '--mirror', remote_url, local_dir] + if lfs_clone: + git_command = ['git', 'lfs', 'clone', '--mirror', remote_url, local_dir] + else: + git_command = ['git', 'clone', '--mirror', remote_url, local_dir] else: - git_command = ['git', 'clone', remote_url, local_dir] + if lfs_clone: + git_command = ['git', 'lfs', 'clone', remote_url, local_dir] + else: + git_command = ['git', 'clone', remote_url, local_dir] logging_subprocess(git_command, None) From 9b1b4a9ebc6d974aeaf98f4eeba55816dd0c2ca2 Mon Sep 17 00:00:00 2001 From: pieterclaerhout Date: Wed, 11 Oct 2017 15:11:14 +0200 Subject: [PATCH 2/3] Added a check to see if git-lfs is installed when doing an LFS clone --- bin/github-backup | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/github-backup b/bin/github-backup index e1d8d80..afa3231 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -471,6 +471,13 @@ def _request_url_error(template, retry_timeout): return False +def check_git_lfs_install(): + exit_code = subprocess.call(['git', 'lfs', 'version']) + if exit_code != 0: + log_error('The argument --lfs requires you to have Git LFS installed.\nYou can get it from https://git-lfs.github.com.') + sys.exit(1) + + def retrieve_repositories(args): log_info('Retrieving repositories') single_request = False @@ -863,6 +870,9 @@ def main(): log_info('Create output directory {0}'.format(output_directory)) mkdir_p(output_directory) + if args.lfs_clone: + check_git_lfs_install() + log_info('Backing up user {0} to {1}'.format(args.user, output_directory)) repositories = retrieve_repositories(args) From bb551a83f4e58a0cce230a865ac00fa1b0c23ce0 Mon Sep 17 00:00:00 2001 From: pieterclaerhout Date: Wed, 11 Oct 2017 15:14:13 +0200 Subject: [PATCH 3/3] Updated the readme --- README.rst | 9 ++++++++- bin/github-backup | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 7b914c3..4ae7d9c 100644 --- a/README.rst +++ b/README.rst @@ -72,7 +72,7 @@ CLI Usage is as follows:: --milestones include milestones in backup --repositories include repository clone in backup --bare clone bare repositories - --lfs clone LFS repositories + --lfs clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com) --wikis include wiki clone in backup --skip-existing skip project if a backup directory exists -L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]] @@ -118,6 +118,13 @@ Note: When you run github-backup, you will be asked whether you want to allow " 1. **Allow:** In this case you will need to click "Allow" each time you run `github-backup` 2. **Always Allow:** In this case, you will not be asked for permission when you run `github-backup` in future. This is less secure, but is required if you want to schedule `github-backup` to run automatically +About Git LFS +============= + +When you use the "--lfs" option, you will need to make sure you have Git LFS installed. + +Instructions on how to do this can be found on https://git-lfs.github.com. + Examples ======== diff --git a/bin/github-backup b/bin/github-backup index afa3231..23d0603 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -211,7 +211,7 @@ def parse_args(): parser.add_argument('--lfs', action='store_true', dest='lfs_clone', - help='clone lfs repositories') + help='clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)') parser.add_argument('--wikis', action='store_true', dest='include_wiki',