mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-05 16:18:02 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b9549ffde | ||
|
|
fb2c3ca921 | ||
|
|
4f4785085d | ||
|
|
76895dcf69 | ||
|
|
1d50a4038b | ||
|
|
9d31ccfba9 | ||
|
|
27a1ba2d04 | ||
|
|
f157ea107f | ||
|
|
a129cc759a | ||
|
|
bb551a83f4 | ||
|
|
9b1b4a9ebc | ||
|
|
e6b6eb8bef | ||
|
|
0b3f120e2b | ||
|
|
990249b80b | ||
|
|
cefb226545 | ||
|
|
ea22ffdf26 | ||
|
|
0f21d7b8a4 | ||
|
|
cb33b9bab7 | ||
|
|
68c48cb0b3 | ||
|
|
922a3c5a6e |
26
CHANGES.rst
26
CHANGES.rst
@@ -1,6 +1,32 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.15.0 (2017-12-11)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Fix arg not defined error. [Edward Pfremmer]
|
||||||
|
|
||||||
|
Ref: https://github.com/josegonzalez/python-github-backup/issues/69
|
||||||
|
|
||||||
|
0.14.0 (2017-10-11)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Added a check to see if git-lfs is installed when doing an LFS clone.
|
||||||
|
[pieterclaerhout]
|
||||||
|
|
||||||
|
- Added support for LFS clones. [pieterclaerhout]
|
||||||
|
|
||||||
|
- Add pypi info to readme. [Albert Wang]
|
||||||
|
|
||||||
|
- Explicitly support python 3 in package description. [Albert Wang]
|
||||||
|
|
||||||
|
- Add couple examples to help new users. [Yusuf Tran]
|
||||||
|
|
||||||
|
0.13.2 (2017-05-06)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Fix remotes while updating repository. [Dima Gerasimov]
|
||||||
|
|
||||||
0.13.1 (2017-04-11)
|
0.13.1 (2017-04-11)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
33
README.rst
33
README.rst
@@ -2,6 +2,8 @@
|
|||||||
github-backup
|
github-backup
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|PyPI| |Python Versions|
|
||||||
|
|
||||||
backup a github user or organization
|
backup a github user or organization
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
@@ -29,7 +31,7 @@ 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] [--bare]
|
[--hooks] [--milestones] [--repositories] [--bare] [--lfs]
|
||||||
[--wikis] [--skip-existing]
|
[--wikis] [--skip-existing]
|
||||||
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
|
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
|
||||||
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
|
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
|
||||||
@@ -70,6 +72,7 @@ CLI Usage is as follows::
|
|||||||
--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
|
--bare clone bare repositories
|
||||||
|
--lfs clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)
|
||||||
--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 ...]]
|
||||||
@@ -114,3 +117,31 @@ 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`
|
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
|
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
|
||||||
|
========
|
||||||
|
|
||||||
|
Backup all repositories::
|
||||||
|
|
||||||
|
export ACCESS_TOKEN=SOME-GITHUB-TOKEN
|
||||||
|
github-backup WhiteHouse --token $ACCESS_TOKEN --organization --output-directory /tmp/white-house --repositories
|
||||||
|
|
||||||
|
Backup a single organization repository with everything else (wiki, pull requests, comments, issues etc)::
|
||||||
|
|
||||||
|
export ACCESS_TOKEN=SOME-GITHUB-TOKEN
|
||||||
|
ORGANIZATION=docker
|
||||||
|
REPO=cli
|
||||||
|
# e.g. git@github.com:docker/cli.git
|
||||||
|
github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO
|
||||||
|
|
||||||
|
.. |PyPI| image:: https://img.shields.io/pypi/v/github-backup.svg
|
||||||
|
:target: https://pypi.python.org/pypi/github-backup/
|
||||||
|
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/github-backup.svg
|
||||||
|
:target: https://github.com/albertyw/github-backup
|
||||||
|
|||||||
@@ -69,11 +69,15 @@ def logging_subprocess(popenargs,
|
|||||||
"""
|
"""
|
||||||
child = subprocess.Popen(popenargs, stdout=subprocess.PIPE,
|
child = subprocess.Popen(popenargs, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, **kwargs)
|
stderr=subprocess.PIPE, **kwargs)
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
log_info("Windows operating system detected - no subprocess logging will be returned")
|
||||||
|
|
||||||
log_level = {child.stdout: stdout_log_level,
|
log_level = {child.stdout: stdout_log_level,
|
||||||
child.stderr: stderr_log_level}
|
child.stderr: stderr_log_level}
|
||||||
|
|
||||||
def check_io():
|
def check_io():
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
return
|
||||||
ready_to_read = select.select([child.stdout, child.stderr],
|
ready_to_read = select.select([child.stdout, child.stderr],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
@@ -208,6 +212,10 @@ def parse_args():
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
dest='bare_clone',
|
dest='bare_clone',
|
||||||
help='clone bare repositories')
|
help='clone bare repositories')
|
||||||
|
parser.add_argument('--lfs',
|
||||||
|
action='store_true',
|
||||||
|
dest='lfs_clone',
|
||||||
|
help='clone LFS repositories (requires Git LFS to be installed, https://git-lfs.github.com)')
|
||||||
parser.add_argument('--wikis',
|
parser.add_argument('--wikis',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='include_wiki',
|
dest='include_wiki',
|
||||||
@@ -467,6 +475,13 @@ def _request_url_error(template, retry_timeout):
|
|||||||
return False
|
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):
|
def retrieve_repositories(args):
|
||||||
log_info('Retrieving repositories')
|
log_info('Retrieving repositories')
|
||||||
single_request = False
|
single_request = False
|
||||||
@@ -540,7 +555,8 @@ def backup_repositories(args, output_directory, repositories):
|
|||||||
repo_url,
|
repo_url,
|
||||||
repo_dir,
|
repo_dir,
|
||||||
skip_existing=args.skip_existing,
|
skip_existing=args.skip_existing,
|
||||||
bare_clone=args.bare_clone)
|
bare_clone=args.bare_clone,
|
||||||
|
lfs_clone=args.lfs_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:
|
||||||
@@ -548,7 +564,8 @@ def backup_repositories(args, output_directory, repositories):
|
|||||||
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)
|
bare_clone=args.bare_clone,
|
||||||
|
lfs_clone=args.lfs_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)
|
||||||
@@ -738,7 +755,8 @@ def fetch_repository(name,
|
|||||||
remote_url,
|
remote_url,
|
||||||
local_dir,
|
local_dir,
|
||||||
skip_existing=False,
|
skip_existing=False,
|
||||||
bare_clone=False):
|
bare_clone=False,
|
||||||
|
lfs_clone=False):
|
||||||
if bare_clone:
|
if bare_clone:
|
||||||
if os.path.exists(local_dir):
|
if os.path.exists(local_dir):
|
||||||
clone_exists = subprocess.check_output(['git',
|
clone_exists = subprocess.check_output(['git',
|
||||||
@@ -769,7 +787,7 @@ def fetch_repository(name,
|
|||||||
|
|
||||||
remotes = subprocess.check_output(['git', 'remote', 'show'],
|
remotes = subprocess.check_output(['git', 'remote', 'show'],
|
||||||
cwd=local_dir)
|
cwd=local_dir)
|
||||||
remotes = [i.strip() for i in remotes.decode('utf-8')]
|
remotes = [i.strip() for i in remotes.decode('utf-8').splitlines()]
|
||||||
|
|
||||||
if 'origin' not in remotes:
|
if 'origin' not in remotes:
|
||||||
git_command = ['git', 'remote', 'rm', 'origin']
|
git_command = ['git', 'remote', 'rm', 'origin']
|
||||||
@@ -780,7 +798,10 @@ def fetch_repository(name,
|
|||||||
git_command = ['git', 'remote', 'set-url', 'origin', remote_url]
|
git_command = ['git', 'remote', 'set-url', 'origin', remote_url]
|
||||||
logging_subprocess(git_command, None, cwd=local_dir)
|
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)
|
logging_subprocess(git_command, None, cwd=local_dir)
|
||||||
else:
|
else:
|
||||||
log_info('Cloning {0} repository from {1} to {2}'.format(
|
log_info('Cloning {0} repository from {1} to {2}'.format(
|
||||||
@@ -788,9 +809,15 @@ def fetch_repository(name,
|
|||||||
masked_remote_url,
|
masked_remote_url,
|
||||||
local_dir))
|
local_dir))
|
||||||
if bare_clone:
|
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:
|
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)
|
logging_subprocess(git_command, None)
|
||||||
|
|
||||||
|
|
||||||
@@ -847,6 +874,9 @@ def main():
|
|||||||
log_info('Create output directory {0}'.format(output_directory))
|
log_info('Create output directory {0}'.format(output_directory))
|
||||||
mkdir_p(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))
|
log_info('Backing up user {0} to {1}'.format(args.user, output_directory))
|
||||||
|
|
||||||
repositories = retrieve_repositories(args)
|
repositories = retrieve_repositories(args)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = '0.13.1'
|
__version__ = '0.15.0'
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -39,6 +39,8 @@ setup(
|
|||||||
'License :: OSI Approved :: MIT License',
|
'License :: OSI Approved :: MIT License',
|
||||||
'Programming Language :: Python :: 2.6',
|
'Programming Language :: Python :: 2.6',
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
|
'Programming Language :: Python :: 3.6',
|
||||||
],
|
],
|
||||||
description='backup a github user or organization',
|
description='backup a github user or organization',
|
||||||
long_description=open_file('README.rst').read(),
|
long_description=open_file('README.rst').read(),
|
||||||
|
|||||||
Reference in New Issue
Block a user