github-backup 0.58.0__py3-none-any.whl → 0.59.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- github_backup/__init__.py +1 -1
- github_backup/cli.py +1 -1
- github_backup/github_backup.py +26 -23
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/METADATA +62 -48
- github_backup-0.59.0.dist-info/RECORD +11 -0
- github_backup-0.58.0.dist-info/RECORD +0 -11
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/WHEEL +0 -0
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/entry_points.txt +0 -0
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/licenses/LICENSE.txt +0 -0
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/top_level.txt +0 -0
- {github_backup-0.58.0.dist-info → github_backup-0.59.0.dist-info}/zip-safe +0 -0
github_backup/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.59.0"
|
github_backup/cli.py
CHANGED
|
@@ -43,7 +43,7 @@ def main():
|
|
|
43
43
|
if args.private and not get_auth(args):
|
|
44
44
|
logger.warning(
|
|
45
45
|
"The --private flag has no effect without authentication. "
|
|
46
|
-
"Use -t/--token
|
|
46
|
+
"Use -t/--token or -f/--token-fine to authenticate."
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
if args.quiet:
|
github_backup/github_backup.py
CHANGED
|
@@ -7,7 +7,6 @@ import base64
|
|
|
7
7
|
import calendar
|
|
8
8
|
import codecs
|
|
9
9
|
import errno
|
|
10
|
-
import getpass
|
|
11
10
|
import json
|
|
12
11
|
import logging
|
|
13
12
|
import os
|
|
@@ -24,7 +23,6 @@ from collections.abc import Generator
|
|
|
24
23
|
from datetime import datetime
|
|
25
24
|
from http.client import IncompleteRead
|
|
26
25
|
from urllib.error import HTTPError, URLError
|
|
27
|
-
from urllib.parse import quote as urlquote
|
|
28
26
|
from urllib.parse import urlencode, urlparse
|
|
29
27
|
from urllib.request import HTTPRedirectHandler, Request, build_opener, urlopen
|
|
30
28
|
|
|
@@ -149,17 +147,6 @@ def mask_password(url, secret="*****"):
|
|
|
149
147
|
def parse_args(args=None):
|
|
150
148
|
parser = argparse.ArgumentParser(description="Backup a github account")
|
|
151
149
|
parser.add_argument("user", metavar="USER", type=str, help="github username")
|
|
152
|
-
parser.add_argument(
|
|
153
|
-
"-u", "--username", dest="username", help="username for basic auth"
|
|
154
|
-
)
|
|
155
|
-
parser.add_argument(
|
|
156
|
-
"-p",
|
|
157
|
-
"--password",
|
|
158
|
-
dest="password",
|
|
159
|
-
help="password for basic auth. "
|
|
160
|
-
"If a username is given but not a password, the "
|
|
161
|
-
"password will be prompted for.",
|
|
162
|
-
)
|
|
163
150
|
parser.add_argument(
|
|
164
151
|
"-t",
|
|
165
152
|
"--token",
|
|
@@ -224,6 +211,13 @@ def parse_args(args=None):
|
|
|
224
211
|
dest="all_starred",
|
|
225
212
|
help="include starred repositories in backup [*]",
|
|
226
213
|
)
|
|
214
|
+
parser.add_argument(
|
|
215
|
+
"--starred-skip-size-over",
|
|
216
|
+
type=int,
|
|
217
|
+
metavar="MB",
|
|
218
|
+
dest="starred_skip_size_over",
|
|
219
|
+
help="skip starred repositories larger than this size in MB",
|
|
220
|
+
)
|
|
227
221
|
parser.add_argument(
|
|
228
222
|
"--watched",
|
|
229
223
|
action="store_true",
|
|
@@ -533,16 +527,6 @@ def get_auth(args, encode=True, for_git_cli=False):
|
|
|
533
527
|
auth = args.token_classic
|
|
534
528
|
else:
|
|
535
529
|
auth = "x-access-token:" + args.token_classic
|
|
536
|
-
elif args.username:
|
|
537
|
-
if not args.password:
|
|
538
|
-
args.password = getpass.getpass()
|
|
539
|
-
if encode:
|
|
540
|
-
password = args.password
|
|
541
|
-
else:
|
|
542
|
-
password = urlquote(args.password)
|
|
543
|
-
auth = args.username + ":" + password
|
|
544
|
-
elif args.password:
|
|
545
|
-
raise Exception("You must specify a username for basic auth")
|
|
546
530
|
|
|
547
531
|
if not auth:
|
|
548
532
|
return None
|
|
@@ -1593,6 +1577,25 @@ def filter_repositories(args, unfiltered_repositories):
|
|
|
1593
1577
|
]
|
|
1594
1578
|
if args.skip_archived:
|
|
1595
1579
|
repositories = [r for r in repositories if not r.get("archived")]
|
|
1580
|
+
if args.starred_skip_size_over is not None:
|
|
1581
|
+
if args.starred_skip_size_over <= 0:
|
|
1582
|
+
logger.warning(
|
|
1583
|
+
"--starred-skip-size-over must be greater than 0, ignoring"
|
|
1584
|
+
)
|
|
1585
|
+
else:
|
|
1586
|
+
size_limit_kb = args.starred_skip_size_over * 1024
|
|
1587
|
+
filtered = []
|
|
1588
|
+
for r in repositories:
|
|
1589
|
+
if r.get("is_starred") and r.get("size", 0) > size_limit_kb:
|
|
1590
|
+
size_mb = r.get("size", 0) / 1024
|
|
1591
|
+
logger.info(
|
|
1592
|
+
"Skipping starred repo {0} ({1:.0f} MB) due to --starred-skip-size-over {2}".format(
|
|
1593
|
+
r.get("full_name", r.get("name")), size_mb, args.starred_skip_size_over
|
|
1594
|
+
)
|
|
1595
|
+
)
|
|
1596
|
+
else:
|
|
1597
|
+
filtered.append(r)
|
|
1598
|
+
repositories = filtered
|
|
1596
1599
|
if args.exclude:
|
|
1597
1600
|
repositories = [
|
|
1598
1601
|
r for r in repositories if "name" not in r or r["name"] not in args.exclude
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: github-backup
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.59.0
|
|
4
4
|
Summary: backup a github user or organization
|
|
5
5
|
Home-page: http://github.com/josegonzalez/python-github-backup
|
|
6
6
|
Author: Jose Diaz-Gonzalez
|
|
@@ -66,23 +66,26 @@ Show the CLI help output::
|
|
|
66
66
|
|
|
67
67
|
CLI Help output::
|
|
68
68
|
|
|
69
|
-
github-backup [-h] [-
|
|
70
|
-
[-
|
|
71
|
-
[-
|
|
72
|
-
[--
|
|
73
|
-
[--
|
|
69
|
+
github-backup [-h] [-t TOKEN_CLASSIC] [-f TOKEN_FINE] [-q] [--as-app]
|
|
70
|
+
[-o OUTPUT_DIRECTORY] [-l LOG_LEVEL] [-i]
|
|
71
|
+
[--incremental-by-files]
|
|
72
|
+
[--starred] [--all-starred] [--starred-skip-size-over MB]
|
|
73
|
+
[--watched] [--followers] [--following] [--all]
|
|
74
|
+
[--issues] [--issue-comments] [--issue-events] [--pulls]
|
|
74
75
|
[--pull-comments] [--pull-commits] [--pull-details]
|
|
75
76
|
[--labels] [--hooks] [--milestones] [--repositories]
|
|
76
|
-
[--bare] [--
|
|
77
|
-
[--
|
|
78
|
-
[-
|
|
79
|
-
[-P] [-F] [--prefer-ssh] [-v]
|
|
77
|
+
[--bare] [--no-prune] [--lfs] [--wikis] [--gists]
|
|
78
|
+
[--starred-gists] [--skip-archived] [--skip-existing]
|
|
79
|
+
[-L [LANGUAGES ...]] [-N NAME_REGEX] [-H GITHUB_HOST]
|
|
80
|
+
[-O] [-R REPOSITORY] [-P] [-F] [--prefer-ssh] [-v]
|
|
80
81
|
[--keychain-name OSX_KEYCHAIN_ITEM_NAME]
|
|
81
82
|
[--keychain-account OSX_KEYCHAIN_ITEM_ACCOUNT]
|
|
82
83
|
[--releases] [--latest-releases NUMBER_OF_LATEST_RELEASES]
|
|
83
|
-
[--skip-prerelease] [--assets]
|
|
84
|
-
[--
|
|
85
|
-
[--throttle-limit THROTTLE_LIMIT]
|
|
84
|
+
[--skip-prerelease] [--assets]
|
|
85
|
+
[--skip-assets-on [SKIP_ASSETS_ON ...]] [--attachments]
|
|
86
|
+
[--throttle-limit THROTTLE_LIMIT]
|
|
87
|
+
[--throttle-pause THROTTLE_PAUSE]
|
|
88
|
+
[--exclude [EXCLUDE ...]]
|
|
86
89
|
USER
|
|
87
90
|
|
|
88
91
|
Backup a github account
|
|
@@ -90,29 +93,29 @@ CLI Help output::
|
|
|
90
93
|
positional arguments:
|
|
91
94
|
USER github username
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
options:
|
|
94
97
|
-h, --help show this help message and exit
|
|
95
|
-
-
|
|
96
|
-
username for basic auth
|
|
97
|
-
-p PASSWORD, --password PASSWORD
|
|
98
|
-
password for basic auth. If a username is given but
|
|
99
|
-
not a password, the password will be prompted for.
|
|
100
|
-
-f TOKEN_FINE, --token-fine TOKEN_FINE
|
|
101
|
-
fine-grained personal access token or path to token
|
|
102
|
-
(file://...)
|
|
103
|
-
-t TOKEN_CLASSIC, --token TOKEN_CLASSIC
|
|
98
|
+
-t, --token TOKEN_CLASSIC
|
|
104
99
|
personal access, OAuth, or JSON Web token, or path to
|
|
105
100
|
token (file://...)
|
|
101
|
+
-f, --token-fine TOKEN_FINE
|
|
102
|
+
fine-grained personal access token (github_pat_....),
|
|
103
|
+
or path to token (file://...)
|
|
104
|
+
-q, --quiet supress log messages less severe than warning, e.g.
|
|
105
|
+
info
|
|
106
106
|
--as-app authenticate as github app instead of as a user.
|
|
107
|
-
-o
|
|
107
|
+
-o, --output-directory OUTPUT_DIRECTORY
|
|
108
108
|
directory at which to backup the repositories
|
|
109
|
-
-l
|
|
109
|
+
-l, --log-level LOG_LEVEL
|
|
110
110
|
log level to use (default: info, possible levels:
|
|
111
111
|
debug, info, warning, error, critical)
|
|
112
112
|
-i, --incremental incremental backup
|
|
113
|
-
--incremental-by-files
|
|
113
|
+
--incremental-by-files
|
|
114
|
+
incremental backup based on modification date of files
|
|
114
115
|
--starred include JSON output of starred repositories in backup
|
|
115
116
|
--all-starred include starred repositories in backup [*]
|
|
117
|
+
--starred-skip-size-over MB
|
|
118
|
+
skip starred repositories larger than this size in MB
|
|
116
119
|
--watched include JSON output of watched repositories in backup
|
|
117
120
|
--followers include JSON output of followers in backup
|
|
118
121
|
--following include JSON output of following users in backup
|
|
@@ -130,20 +133,22 @@ CLI Help output::
|
|
|
130
133
|
--milestones include milestones in backup
|
|
131
134
|
--repositories include repository clone in backup
|
|
132
135
|
--bare clone bare repositories
|
|
136
|
+
--no-prune disable prune option for git fetch
|
|
133
137
|
--lfs clone LFS repositories (requires Git LFS to be
|
|
134
138
|
installed, https://git-lfs.github.com) [*]
|
|
135
139
|
--wikis include wiki clone in backup
|
|
136
140
|
--gists include gists in backup [*]
|
|
137
141
|
--starred-gists include starred gists in backup [*]
|
|
142
|
+
--skip-archived skip project if it is archived
|
|
138
143
|
--skip-existing skip project if a backup directory exists
|
|
139
|
-
-L
|
|
144
|
+
-L, --languages [LANGUAGES ...]
|
|
140
145
|
only allow these languages
|
|
141
|
-
-N
|
|
146
|
+
-N, --name-regex NAME_REGEX
|
|
142
147
|
python regex to match names against
|
|
143
|
-
-H
|
|
148
|
+
-H, --github-host GITHUB_HOST
|
|
144
149
|
GitHub Enterprise hostname
|
|
145
150
|
-O, --organization whether or not this is an organization user
|
|
146
|
-
-R
|
|
151
|
+
-R, --repository REPOSITORY
|
|
147
152
|
name of repository to limit backup to
|
|
148
153
|
-P, --private include private repositories [*]
|
|
149
154
|
-F, --fork include forked repositories [*]
|
|
@@ -158,19 +163,16 @@ CLI Help output::
|
|
|
158
163
|
--releases include release information, not including assets or
|
|
159
164
|
binaries
|
|
160
165
|
--latest-releases NUMBER_OF_LATEST_RELEASES
|
|
161
|
-
include certain number of the latest releases;
|
|
162
|
-
|
|
163
|
-
--skip-prerelease skip prerelease and draft versions; only applies if
|
|
166
|
+
include certain number of the latest releases; only
|
|
167
|
+
applies if including releases
|
|
168
|
+
--skip-prerelease skip prerelease and draft versions; only applies if
|
|
169
|
+
including releases
|
|
164
170
|
--assets include assets alongside release information; only
|
|
165
171
|
applies if including releases
|
|
166
|
-
--skip-assets-on [
|
|
167
|
-
skip asset downloads for these repositories
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
to issues/attachments/{issue_number}/ and
|
|
171
|
-
pulls/attachments/{pull_number}/ directories
|
|
172
|
-
--exclude [REPOSITORY [REPOSITORY ...]]
|
|
173
|
-
names of repositories to exclude from backup.
|
|
172
|
+
--skip-assets-on [SKIP_ASSETS_ON ...]
|
|
173
|
+
skip asset downloads for these repositories
|
|
174
|
+
--attachments download user-attachments from issues and pull
|
|
175
|
+
requests
|
|
174
176
|
--throttle-limit THROTTLE_LIMIT
|
|
175
177
|
start throttling of GitHub API requests after this
|
|
176
178
|
amount of API requests remain
|
|
@@ -178,6 +180,8 @@ CLI Help output::
|
|
|
178
180
|
wait this amount of seconds when API request
|
|
179
181
|
throttling is active (default: 30.0, requires
|
|
180
182
|
--throttle-limit to be set)
|
|
183
|
+
--exclude [EXCLUDE ...]
|
|
184
|
+
names of repositories to exclude
|
|
181
185
|
|
|
182
186
|
|
|
183
187
|
Usage Details
|
|
@@ -186,13 +190,13 @@ Usage Details
|
|
|
186
190
|
Authentication
|
|
187
191
|
--------------
|
|
188
192
|
|
|
189
|
-
|
|
193
|
+
GitHub requires token-based authentication for API access. Password authentication was `removed in November 2020 <https://developer.github.com/changes/2020-02-14-deprecating-password-auth/>`_.
|
|
190
194
|
|
|
191
|
-
|
|
195
|
+
The positional argument ``USER`` specifies the user or organization account you wish to back up.
|
|
192
196
|
|
|
193
|
-
**
|
|
197
|
+
**Fine-grained tokens** (``-f TOKEN_FINE``) are recommended for most use cases, especially long-running backups (e.g. cron jobs), as they provide precise permission control.
|
|
194
198
|
|
|
195
|
-
|
|
199
|
+
**Classic tokens** (``-t TOKEN``) are `slightly less secure <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic>`_ as they provide very coarse-grained permissions.
|
|
196
200
|
|
|
197
201
|
|
|
198
202
|
Fine Tokens
|
|
@@ -320,10 +324,20 @@ All is not everything
|
|
|
320
324
|
|
|
321
325
|
The ``--all`` argument does not include: cloning private repos (``-P, --private``), cloning forks (``-F, --fork``), cloning starred repositories (``--all-starred``), ``--pull-details``, cloning LFS repositories (``--lfs``), cloning gists (``--gists``) or cloning starred gist repos (``--starred-gists``). See examples for more.
|
|
322
326
|
|
|
323
|
-
|
|
324
|
-
|
|
327
|
+
Starred repository size
|
|
328
|
+
-----------------------
|
|
329
|
+
|
|
330
|
+
Using the ``--all-starred`` argument to clone all starred repositories may use a large amount of storage space.
|
|
331
|
+
|
|
332
|
+
To see your starred repositories sorted by size (requires `GitHub CLI <https://cli.github.com>`_)::
|
|
333
|
+
|
|
334
|
+
gh api user/starred --paginate --jq 'sort_by(-.size)[]|"\(.full_name) \(.size/1024|round)MB"'
|
|
335
|
+
|
|
336
|
+
To limit which starred repositories are cloned, use ``--starred-skip-size-over SIZE`` where SIZE is in MB. For example, ``--starred-skip-size-over 500`` will skip any starred repository where the git repository size (code and history) exceeds 500 MB. Note that this size limit only applies to the repository itself, not issues, release assets or other metadata. This filter only affects starred repositories; your own repositories are always included regardless of size.
|
|
337
|
+
|
|
338
|
+
For finer control, avoid using ``--assets`` with starred repos, or use ``--skip-assets-on`` for specific repositories with large release binaries.
|
|
325
339
|
|
|
326
|
-
|
|
340
|
+
Alternatively, consider just storing links to starred repos in JSON format with ``--starred``.
|
|
327
341
|
|
|
328
342
|
Incremental Backup
|
|
329
343
|
------------------
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
github_backup/__init__.py,sha256=HMyZ2jNndR4_RS4EcSAHrVoKBifJVKSLuqmMuKnl_JI,23
|
|
2
|
+
github_backup/__main__.py,sha256=3yorCiC63maaxbjdtaeAs-G-yAAxKSO3mprhGfa1Fho,271
|
|
3
|
+
github_backup/cli.py,sha256=ifnOne5AaEI7laofgIq3geURJtvbA-bzxSQgLcmZgd0,2345
|
|
4
|
+
github_backup/github_backup.py,sha256=VkUaqxAMT3ooQ4xGp54xpUtAJL4h4zZ8b_-EtrFi2T4,81615
|
|
5
|
+
github_backup-0.59.0.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
6
|
+
github_backup-0.59.0.dist-info/METADATA,sha256=_IyD8iBRAXp-Kkz1Ru0pkwjzVNDECjB6jKN6IR3n-Sk,26421
|
|
7
|
+
github_backup-0.59.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
github_backup-0.59.0.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
|
|
9
|
+
github_backup-0.59.0.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
10
|
+
github_backup-0.59.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
11
|
+
github_backup-0.59.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
github_backup/__init__.py,sha256=oIkJTCdzxBkcFHWQdIvMrmJih4tpnF1BnfoNPd1mB48,23
|
|
2
|
-
github_backup/__main__.py,sha256=3yorCiC63maaxbjdtaeAs-G-yAAxKSO3mprhGfa1Fho,271
|
|
3
|
-
github_backup/cli.py,sha256=zMUU0pTnh9KPqv8K--KNpUNf-yaA1qWeI6AdC1KVrn8,2361
|
|
4
|
-
github_backup/github_backup.py,sha256=Q3EcCwO7X8v5MPdWilx0zsJa8FLUINzSI8bjHw08O50,81287
|
|
5
|
-
github_backup-0.58.0.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
6
|
-
github_backup-0.58.0.dist-info/METADATA,sha256=wYRqf6V7hjtir_td4uYuK296O5KHeqpCPGhsr-ndnK8,25921
|
|
7
|
-
github_backup-0.58.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
github_backup-0.58.0.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
|
|
9
|
-
github_backup-0.58.0.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
10
|
-
github_backup-0.58.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
11
|
-
github_backup-0.58.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|