Sha256: 71b52d127d218a7157c5976de0201dff3b77c9d1be9131b177bc38125d3ea119

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')

require 'logger'
require 'optparse'

require 'datadog_backup'
require 'dogapi'

$stdout.sync = $stderr.sync = true
LOGGER = Logger.new($stderr) unless defined?(LOGGER)
LOGGER.level = Logger::INFO

##
# Default parameters
@options = {
  action: nil,
  datadog_api_key: ENV.fetch('DATADOG_API_KEY'),
  datadog_app_key: ENV.fetch('DATADOG_APP_KEY'),
  backup_dir: File.join(ENV.fetch('PWD'), 'backup'),
  diff_format: :color,
  resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors],
  output_format: :yaml,
  logger: LOGGER
}

def prereqs
  ARGV << '--help' if ARGV.empty?

  options = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} <backup|diffs>"
    opts.separator ''
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit 0
    end
    opts.on('--debug', 'debug logging') do
      LOGGER.level = Logger::DEBUG
    end
    opts.on('--backup-dir PATH', '`backup` by default') do |path|
      @options[:backup_dir] = path
    end
    opts.on('--monitors-only') do
      @options[:resources] = [DatadogBackup::Monitors]
    end
    opts.on('--dashboards-only') do
      @options[:resources] = [DatadogBackup::Dashboards]
    end
    opts.on('--json', 'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix.') do
      @options[:output_format] = :json
    end
    opts.on('--no-color', 'removes colored output from diff format') do
      @options[:diff_format] = nil
    end
    opts.on('--diff-format FORMAT', 'one of `color`, `html_simple`, `html`') do |format|
      @options[:diff_format] = format.to_sym
    end
  end
  options.parse!

  @options[:action] = ARGV.first
  if %w[backup diffs restore].include?(@options[:action])
  else
    puts options
    exit 0
  end
end

prereqs

DatadogBackup::Cli.new(@options).run!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datadog_backup-0.9.0 bin/datadog_backup