lib/github_snapshot/snapshot.rb in github_snapshot-0.1.1 vs lib/github_snapshot/snapshot.rb in github_snapshot-0.1.2
- old
+ new
@@ -8,31 +8,26 @@
@@logger.level = Logger::INFO
@@logger.datetime_format = '%Y-%m-%d %H:%M:%S '
@@git_clone_cmd = "git clone --quiet --mirror"
@@time_now = Time.now.getutc.strftime("%Y%m%d%H%M")
@@releases_to_keep
+ @@git_clone_timeout
- def self.logger
- @@logger
- end
+ def self.logger; @@logger; end
+ def self.git_clone_cmd; @@git_clone_cmd; end
+ def self.time_now; @@time_now; end
+ def self.releases_to_keep; @@releases_to_keep; end
+ def self.git_clone_timeout; @@git_clone_timeout; end
- def self.git_clone_cmd
- @@git_clone_cmd
- end
-
- def self.time_now
- @@time_now
- end
-
- def self.releases_to_keep
- @@releases_to_keep
- end
-
def self.releases_to_keep=(releases_to_keep)
@@releases_to_keep = releases_to_keep
end
+ def self.git_clone_timeout=(git_clone_timeout)
+ @@git_clone_timeout = git_clone_timeout
+ end
+
def self.exec(cmd)
Utilities.exec cmd, @@logger
end
class Snapshot
@@ -47,11 +42,12 @@
@username = config['username']
@password = config['password']
@organizations = config['organizations']
@s3_bucket = config['s3bucket']
@backup_folder = config['backup_folder']
- GithubSnapshot.releases_to_keep = config['releases_to_keep']
+ GithubSnapshot.releases_to_keep = config['releases_to_keep']
+ GithubSnapshot.git_clone_timeout = config['git_clone_timeout']
@github = Github.new do |config|
config.login = username
config.password = password
config.auto_pagination = true
@@ -73,10 +69,15 @@
GithubSnapshot.exec "mkdir -p #{backup_folder}"
end
def download_from_s3
GithubSnapshot.logger.info "downloading fom s3"
- GithubSnapshot.exec "s3cmd sync --delete-removed s3://#{s3_bucket}/ #{backup_folder}/"
+ begin
+ GithubSnapshot.exec "s3cmd sync --delete-removed s3://#{s3_bucket}/ #{backup_folder}/"
+ rescue Utilities::ExecError
+ GithubSnapshot.logger.info "s3cmd doesn't respect exit status\n"\
+ "there is a good chance that the sync was successful"
+ end
end
def backup_orgs
Dir.chdir "#{backup_folder}"
organizations.each do |org|