PageRenderTime 61ms CodeModel.GetById 2ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/bitbucket-backup

https://bitbucket.org/seth/bitbucket-backup
Ruby | 71 lines | 61 code | 9 blank | 1 comment | 1 complexity | 8652015cdc5b73f0e7e21068aacd47cc MD5 | raw file
Possible License(s): 0BSD
  1. #!/usr/bin/env ruby
  2. require "highline/import"
  3. require "bitbucket-backup"
  4. require "optparse"
  5. require "yaml"
  6. options = {}
  7. parser = OptionParser.new do |opts|
  8. cmd = File.basename($0)
  9. opts.banner = "usage: #{cmd} [options] /path/to/backupdir"
  10. opts.on("-a", "--all-repos", "Backup all visible repos to user.") do
  11. options["all_repos"] = true
  12. end
  13. opts.on("-c", "--config FILE", "Path to config file.") do |config_file|
  14. options["config_file"] = config_file
  15. end
  16. opts.on("-u", "--username USERNAME", "Username for account to be backed up.") do |username|
  17. options["username"] = username
  18. end
  19. opts.on("-h", "--help", "Show this help message and exit.") do
  20. puts opts
  21. exit
  22. end
  23. opts.on("-v", "--version", "Display the program's version and exit.") do
  24. puts "#{cmd} (version #{Bitbucket::Backup::VERSION})"
  25. exit
  26. end
  27. end
  28. parser.parse!
  29. config = {}
  30. if options["config_file"]
  31. begin
  32. path = File.expand_path(options["config_file"])
  33. config = YAML.load_file(path)
  34. unless config
  35. puts "Error: invalid config file: #{path}."
  36. exit
  37. end
  38. rescue YAML::SyntaxError, StandardError
  39. puts "Error: invalid config file: #{path}."
  40. exit
  41. end
  42. end
  43. config.merge!(options)
  44. if ARGV.empty? || !config["username"]
  45. puts parser.banner
  46. exit
  47. end
  48. if !config["password"]
  49. config["password"] = ask("Password: ") do |q|
  50. q.echo = false
  51. end
  52. end
  53. Bitbucket::Backup.run(config["username"], config["password"], ARGV.first, config["all_repos"] || false)