backup_on_the_go 0.1.5 → 0.2.2
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.
- checksums.yaml +6 -14
- data/README.md +14 -1
- data/lib/backup_on_the_go.rb +80 -19
- data/lib/backup_on_the_go/version.rb +2 -2
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NzcyZWM0NjZhY2NkYTU1YzRjMmVmODgyNjFkZDc5ZDA0MDQ4ODUxNDllYTFm
|
10
|
-
YTUyZDc2MGVhMjRlZDIzM2MyMTMxYTI5NGJhNWFmMmQ2NzU0ODUxMjQ1OWFj
|
11
|
-
OGJjOTdkMjdjMWMxZGM2ZGVhMGFkYWRhOGU2ZGY5OGFiNzRhZDY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZjUyZGFiMDcyMWM3MTMwMjg4Zjk0MDEzOGJlMjNhYWM1OGY5OWMwYzRhNmNj
|
14
|
-
ODIyM2ZjMDhhOTVhMTJiMmM5ZWYzMTYzMDZhNDg0MDEzNDM5NzIzZmFiYzMz
|
15
|
-
MWFkM2Y4ZDZiMGU3OTIzNTRhNDE4N2QzMWQxODJjOGE0YjdjODM=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74d66dc8e67ff27c2920c630c0cb04f4e11f7377
|
4
|
+
data.tar.gz: 442f688f41e905f920ae82f05a340421385954e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed89ec5e52c44b13810ac322d4098dd4ea0ffda0936822cf72c9400c01bdd2192c8639464167a76861ff5810dcf2acb8a842a3c008b0f5b9353b6aa3efdc18bb
|
7
|
+
data.tar.gz: 77c41424789d658bfe81782ea151091e14f38f92c2d55d152c1230f7f41eb39aac9b5d261ee3a0dd0ea686727003cdd534d5ac9a696a73f484f5d848b9f0ecd7
|
data/README.md
CHANGED
@@ -61,9 +61,22 @@ dyno instead of the web dyno:
|
|
61
61
|
Done!
|
62
62
|
|
63
63
|
|
64
|
+
## Real World Examples
|
65
|
+
|
66
|
+
For a real world example, you can check [my backup BitBucket Account][]. For
|
67
|
+
another example of backing up organizations, see EditorConfig on [GitHub][4]
|
68
|
+
and [BitBucket][5].
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
[](http://githalytics.com/xuhdev/backup-on-the-go)
|
73
|
+
|
64
74
|
[1]: https://rubygems.org/gems/backup_on_the_go
|
65
75
|
[2]: http://rubydoc.info/github/xuhdev/backup-on-the-go/master/frames
|
66
76
|
[3]: http://rubydoc.info/github/xuhdev/backup-on-the-go/master/BackupOnTheGo.backup
|
67
|
-
[
|
77
|
+
[4]: https://github.com/editorconfig
|
78
|
+
[5]: https://bitbucket.org/editorconfig
|
68
79
|
[Heroku Toolbelt]: https://toolbelt.heroku.com/
|
80
|
+
[My backup BitBucket Account]: https://bitbucket.org/xuhdev-backup
|
81
|
+
[heroku_signup]: https://id.heroku.com/signup
|
69
82
|
[scale your dyno formation]: https://devcenter.heroku.com/articles/scaling
|
data/lib/backup_on_the_go.rb
CHANGED
@@ -11,6 +11,7 @@ module BackupOnTheGo #:nodoc:#
|
|
11
11
|
|
12
12
|
DEFAULT_CONFIG = {
|
13
13
|
:backup_fork => false,
|
14
|
+
:backup_private => false,
|
14
15
|
:git_cmd => 'git',
|
15
16
|
:github_repos_max => '200',
|
16
17
|
:is_private => true,
|
@@ -19,29 +20,43 @@ module BackupOnTheGo #:nodoc:#
|
|
19
20
|
:verbose => true
|
20
21
|
}.freeze
|
21
22
|
|
22
|
-
|
23
|
+
|
24
|
+
# Back up GitHub repositories to BitBucket.
|
23
25
|
#
|
24
26
|
# = Parameters
|
25
|
-
# * <tt>:backup_fork</tt> - Optional boolean - <tt>true</tt> to
|
27
|
+
# * <tt>:backup_fork</tt> - Optional boolean - <tt>true</tt> to back up forked repositories, <tt>false</tt> to skip them. Default is <tt>false</tt>.
|
28
|
+
# * <tt>:backup_private</tt> - Optional boolean - <tt>true</tt> to back up private repositories, <tt>false</tt> to NOT back up private repositories. Default is <tt>false</tt>.
|
26
29
|
# * <tt>:bitbucket_password</tt> - Optional string - The password to access the BitBucket account. If not specified, a prompt will show up to ask for the password.
|
27
30
|
# * <tt>:bitbucket_repos_owner</tt> - Optional string - Owner of the backup repositories on BitBucket. The owner could be a team. If not specified, <tt>:bitbucket_user</tt> will be used.
|
28
31
|
# * <tt>:bitbucket_user</tt> - *Required* string if <tt>:user</tt> is not specified - The user name on BitBucket. If not specified, <tt>:user</tt> will be used.
|
29
32
|
# * <tt>:git_cmd</tt> - Optional string - The git command you want to use. Default is 'git'.
|
33
|
+
# * <tt>:github_password</tt> - Optional string - When backup_private is set to true, this is the password used to access the GitHub account. If not specified, a prompt will show up to ask for the password.
|
30
34
|
# * <tt>:github_repos_max</tt> - Optional string - The max number of your GitHub repos, since GitHub API requires to give a repo number upper limit. Usually you don't need to set up this number unless you have more than 200 repositories. Default is <tt>"200"</tt>.
|
31
35
|
# * <tt>:github_repos_owner</tt> - Optional string - The owner of the repositories that need to be backed up. The owner could be an organization. If not specified, <tt>:github_user</tt> will be used.
|
32
36
|
# * <tt>:github_user</tt> - *Required* string if <tt>:user</tt> is not specified - The user name on GitHub. If not specified, <tt>:user</tt> will be used.
|
33
|
-
# * <tt>:is_private</tt> - Optional boolean - <tt>true</tt> to make the backup repositories private
|
34
|
-
# * <tt>:no_public_forks</tt> - Optional boolean - <tt>true</tt> to forbid public fork for the backup repositories, <tt>false</tt> to allow public fork. Default is <tt>true</tt>.
|
37
|
+
# * <tt>:is_private</tt> - Optional boolean - <tt>true</tt> to make the backup repositories private even if the corresponding github repositories are public; <tt>false</tt> to keep the original privacy. Default is <tt>true</tt>.
|
38
|
+
# * <tt>:no_public_forks</tt> - Optional boolean - <tt>true</tt> to forbid public fork for the backup repositories, <tt>false</tt> to allow public fork. Only valid for public backup repositories. Default is <tt>true</tt>.
|
35
39
|
# * <tt>:repo_prefix</tt> - Optional string - The prefix you wanna prepend to the backup repository names. In this way, if you have a repository with the same name on BitBucket, it won't get flushed. Default is <tt>"backup-on-the-go-"</tt>.
|
36
40
|
# * <tt>:user</tt> - *Required* string if <tt>:github_user</tt> and <tt>:bitbucket_user</tt> are not both specified - The user name of GitHub and BitBucket (if they are same for you). If you want to use different user names on GitHub and BitBucket, please specify <tt>:github_user</tt> and <tt>:bitbucket_user</tt> instead.
|
37
41
|
# * <tt>:verbose</tt> - Optional boolean - <tt>true</tt> to print additional information and <tt>false</tt> to suppress them. Default is <tt>true</tt>.
|
38
42
|
#
|
39
43
|
# = Examples
|
40
44
|
#
|
41
|
-
# # Back up personal repositories
|
45
|
+
# # Back up personal public repositories only
|
46
|
+
# BackupOnTheGo.backup :github_user => 'github_user_name',
|
47
|
+
# :bitbucket_user => 'bitbucket_user_name',
|
48
|
+
# :is_private => false, # make backup repositories public
|
49
|
+
# :bitbucket_password => 'bitbucket_password',
|
50
|
+
# :repo_prefix => '' # don't need any prefix
|
51
|
+
#
|
52
|
+
# = Examples
|
53
|
+
#
|
54
|
+
# # Back up personal public and private repositories
|
42
55
|
# BackupOnTheGo.backup :github_user => 'github_user_name',
|
43
56
|
# :bitbucket_user => 'bitbucket_user_name',
|
57
|
+
# :backup_private => true, # back up private repositories
|
44
58
|
# :is_private => false, # make backup repositories public
|
59
|
+
# :github_password => 'github_password',
|
45
60
|
# :bitbucket_password => 'bitbucket_password',
|
46
61
|
# :repo_prefix => '' # don't need any prefix
|
47
62
|
#
|
@@ -77,11 +92,19 @@ module BackupOnTheGo #:nodoc:#
|
|
77
92
|
config[:bitbucket_repos_owner] = config[:bitbucket_user]
|
78
93
|
end
|
79
94
|
|
80
|
-
# Ask for the
|
95
|
+
# Ask for the passwords if they are not specified
|
96
|
+
if config[:backup_private] and !config.has_key?(:github_password)
|
97
|
+
config[:github_password] = ask("Enter your GitHub password for #{config[:github_user]}: ") { |q| q.echo = false }
|
98
|
+
end
|
81
99
|
unless config.has_key?(:bitbucket_password)
|
82
|
-
config[:bitbucket_password] = ask("Enter your BitBucket password: ") { |q| q.echo = false }
|
100
|
+
config[:bitbucket_password] = ask("Enter your BitBucket password for #{config[:bitbucket_user]}: ") { |q| q.echo = false }
|
83
101
|
end
|
84
102
|
|
103
|
+
# print an empty line
|
104
|
+
puts
|
105
|
+
|
106
|
+
# log in BitBucket
|
107
|
+
|
85
108
|
bb = BitBucket.new :login => config[:bitbucket_user], :password => config[:bitbucket_password]
|
86
109
|
|
87
110
|
backup_repo_names = Array.new
|
@@ -92,13 +115,12 @@ module BackupOnTheGo #:nodoc:#
|
|
92
115
|
end
|
93
116
|
end
|
94
117
|
|
95
|
-
#
|
96
|
-
|
97
|
-
:per_page => config[:github_repos_max]
|
98
|
-
|
99
|
-
gh_repos.each do |repo|
|
118
|
+
# handling each GitHub repo, used below
|
119
|
+
repo_each_proc = Proc.new do |repo|
|
100
120
|
next if repo.fork && !config[:backup_fork]
|
101
121
|
|
122
|
+
is_private = config[:is_private] || repo.private?
|
123
|
+
|
102
124
|
puts "Backing up #{repo.name}..." if config[:verbose]
|
103
125
|
|
104
126
|
backup_repo_name = "#{config[:repo_prefix]}#{repo.name}"
|
@@ -108,7 +130,8 @@ module BackupOnTheGo #:nodoc:#
|
|
108
130
|
puts "Creating new repository #{config[:bitbucket_repos_owner]}/#{backup_repo_name}..." if config[:verbose]
|
109
131
|
begin
|
110
132
|
bb.repos.create :name => backup_repo_name, :owner => config[:bitbucket_repos_owner],
|
111
|
-
:scm => 'git', :is_private =>
|
133
|
+
:scm => 'git', :is_private => is_private,
|
134
|
+
:no_public_forks => config[:no_public_forks]
|
112
135
|
rescue
|
113
136
|
puts_warning "Creation of repository #{config[:bitbucket_repos_owner]}/#{backup_repo_name} failed."
|
114
137
|
end
|
@@ -120,17 +143,22 @@ module BackupOnTheGo #:nodoc:#
|
|
120
143
|
bb.repos.edit config[:bitbucket_repos_owner], backup_repo_name,
|
121
144
|
:website => repo.homepage,
|
122
145
|
:description => repo.description,
|
123
|
-
:is_private =>
|
124
|
-
:no_public_forks => config[:no_public_forks]
|
125
|
-
rescue
|
146
|
+
:is_private => is_private,
|
147
|
+
:no_public_forks => is_private && config[:no_public_forks]
|
148
|
+
rescue Exception => e
|
126
149
|
puts_warning "Failed to update information for #{config[:bitbucket_repos_owner]}/#{backup_repo_name}"
|
150
|
+
puts e.message
|
127
151
|
end
|
128
152
|
|
129
153
|
Dir.mktmpdir do |dir|
|
130
|
-
|
131
|
-
|
154
|
+
# clone git url
|
155
|
+
clone_url = repo.clone_url
|
156
|
+
clone_url.sub!(/https:\/\//,
|
157
|
+
"https://#{config[:github_user]}:#{config[:github_password]}@") if config[:backup_private]
|
158
|
+
cmd = "#{config[:git_cmd]} clone --mirror '#{clone_url}' #{dir}/tmp-repo"
|
159
|
+
puts "Executing [#{config[:git_cmd]} clone --mirror 'https://#{config[:bitbucket_user]}:your_password@github.com/#{config[:github_repos_owner]}/#{repo.name}.git' #{dir}/tmp-repo]" if config[:verbose]
|
132
160
|
unless system(cmd)
|
133
|
-
puts_warning "'git clone' failed for #{
|
161
|
+
puts_warning "'git clone' failed for #{clone_url}\n"
|
134
162
|
break
|
135
163
|
end
|
136
164
|
|
@@ -174,6 +202,39 @@ module BackupOnTheGo #:nodoc:#
|
|
174
202
|
puts
|
175
203
|
end
|
176
204
|
end
|
205
|
+
|
206
|
+
# obtain github repos
|
207
|
+
if config[:backup_private]
|
208
|
+
gh = Github.new :login => config[:github_user], :password => config[:github_password]
|
209
|
+
else
|
210
|
+
gh = Github.new
|
211
|
+
end
|
212
|
+
|
213
|
+
# private repos
|
214
|
+
if config[:backup_private]
|
215
|
+
puts "Backing up private repositories...\n".green
|
216
|
+
|
217
|
+
gh_repos = gh.repos.list :per_page => config[:github_repos_max]
|
218
|
+
|
219
|
+
gh_repos.each do |repo|
|
220
|
+
# only back up private repositories with the owner specified
|
221
|
+
if repo.owner.login == config[:github_repos_owner] and repo.private?
|
222
|
+
repo_each_proc.call(repo)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# public repos
|
228
|
+
puts "Backing up public repositories...\n".green
|
229
|
+
|
230
|
+
gh_repos = gh.repos.list :user => config[:github_repos_owner],
|
231
|
+
:per_page => config[:github_repos_max]
|
232
|
+
|
233
|
+
gh_repos.each do |repo|
|
234
|
+
repo_each_proc.call(repo)
|
235
|
+
end
|
236
|
+
|
237
|
+
|
177
238
|
end
|
178
239
|
|
179
240
|
private
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup_on_the_go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hong Xu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github_api
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.10.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.10.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: highline
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6.
|
33
|
+
version: 1.6.19
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6.
|
40
|
+
version: 1.6.19
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bitbucket_rest_api
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,17 +88,17 @@ require_paths:
|
|
88
88
|
- lib
|
89
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.0.
|
101
|
+
rubygems_version: 2.0.6
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Backup GitHub repositories to BitBucket
|