Class: GithubSnapshot::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/github_snapshot/snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = "config.yml") ⇒ Snapshot

Returns a new instance of Snapshot.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/github_snapshot/snapshot.rb', line 39

def initialize(config_file="config.yml")
  config = YAML.load(File.read(config_file))

  @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.git_clone_timeout = config['git_clone_timeout']

  @github = Github.new do |config|
    config.           = username
    config.password        = password
    config.auto_pagination = true
  end
end

Instance Attribute Details

#backup_folderObject (readonly)

Returns the value of attribute backup_folder.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def backup_folder
  @backup_folder
end

#git_clone_cmdObject (readonly)

Returns the value of attribute git_clone_cmd.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def git_clone_cmd
  @git_clone_cmd
end

#githubObject (readonly)

Returns the value of attribute github.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def github
  @github
end

#loggerObject (readonly)

Returns the value of attribute logger.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def logger
  @logger
end

#organizationsObject (readonly)

Returns the value of attribute organizations.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def organizations
  @organizations
end

#passwordObject (readonly)

Returns the value of attribute password.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def password
  @password
end

#releases_to_keepObject (readonly)

Returns the value of attribute releases_to_keep.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def releases_to_keep
  @releases_to_keep
end

#s3_bucketObject (readonly)

Returns the value of attribute s3_bucket.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def s3_bucket
  @s3_bucket
end

#time_nowObject (readonly)

Returns the value of attribute time_now.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def time_now
  @time_now
end

#usernameObject (readonly)

Returns the value of attribute username.



36
37
38
# File 'lib/github_snapshot/snapshot.rb', line 36

def username
  @username
end

Instance Method Details

#backupObject



57
58
59
60
61
62
63
64
65
# File 'lib/github_snapshot/snapshot.rb', line 57

def backup
  create_backup_folder
  download_from_s3
  backup_orgs
  upload_to_s3

  total_size = %x[ du -sh #{backup_folder} | cut -f1 ]
  GithubSnapshot.logger.info "backup finished, total size is #{total_size}"
end