bkwrapper 0.0.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 +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -0
- data/Rakefile +9 -0
- data/bin/bkwrapper +21 -0
- data/bkwrapper.gemspec +23 -0
- data/lib/bkwrapper/backup/backup_executor.rb +40 -0
- data/lib/bkwrapper/backup/compressor.rb +13 -0
- data/lib/bkwrapper/backup/mysql_backupper.rb +33 -0
- data/lib/bkwrapper/backup/pg_backupper.rb +33 -0
- data/lib/bkwrapper/base.rb +35 -0
- data/lib/bkwrapper/s3/uploader.rb +30 -0
- data/lib/bkwrapper.rb +4 -0
- data/spec/bkwrapper/backup/backup_executor_spec.rb +27 -0
- data/spec/bkwrapper/backup/compressor_spec.rb +23 -0
- data/spec/bkwrapper/backup/mysql_backupper_spec.rb +27 -0
- data/spec/bkwrapper/backup/pg_backupper_spec.rb +27 -0
- metadata +94 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 81757aa385e7a3e7f37ecc019136a8bdf937c646
         | 
| 4 | 
            +
              data.tar.gz: b84831acb796a480b055e5dac18d521cd588d845
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 1f8edc814a86991fdca8c8a8288632755e95b89b7d91445fe971a904951389dc87385842786368dd7235b323827d9877bf545ab0bf0acc47a1654052c5920e44
         | 
| 7 | 
            +
              data.tar.gz: d64da2e1370352b3e7e7b624d6b5bbc7bbdf8d1cdf8569228966a6c38414670a47a44d463d33af7c763dacb71b50c129a3b4525aa64929b47eb9dc26e2f86f0f
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                bkwrapper (0.0.0)
         | 
| 5 | 
            +
                  aws-sdk (~> 2)
         | 
| 6 | 
            +
                  rake (~> 10.4.2)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            GEM
         | 
| 9 | 
            +
              remote: https://rubygems.org/
         | 
| 10 | 
            +
              specs:
         | 
| 11 | 
            +
                aws-sdk (2.0.31)
         | 
| 12 | 
            +
                  aws-sdk-resources (= 2.0.31)
         | 
| 13 | 
            +
                aws-sdk-core (2.0.31)
         | 
| 14 | 
            +
                  builder (~> 3.0)
         | 
| 15 | 
            +
                  jmespath (~> 1.0)
         | 
| 16 | 
            +
                  multi_json (~> 1.0)
         | 
| 17 | 
            +
                  multi_xml (~> 0.5)
         | 
| 18 | 
            +
                aws-sdk-resources (2.0.31)
         | 
| 19 | 
            +
                  aws-sdk-core (= 2.0.31)
         | 
| 20 | 
            +
                builder (3.2.2)
         | 
| 21 | 
            +
                jmespath (1.0.2)
         | 
| 22 | 
            +
                  multi_json (~> 1.0)
         | 
| 23 | 
            +
                multi_json (1.11.0)
         | 
| 24 | 
            +
                multi_xml (0.5.5)
         | 
| 25 | 
            +
                rake (10.4.2)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            PLATFORMS
         | 
| 28 | 
            +
              ruby
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            DEPENDENCIES
         | 
| 31 | 
            +
              bkwrapper!
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2015 Filipe Chagas
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            #Bkwrapper
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            On my work, we have several projects, each one running on top of different databases - postgres, mysql, mongodb... - and I always forget the backup command for each one of them.
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            That's why I've written this gem: To wrap up the backup commands so that I only have to remember one backup syntax.
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            As part of my needs, it also uplods the generated backup file to an amazon s3 account.
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ##Usage
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
             | 
| 14 | 
            +
                bkwrapper [pg|mysql] [name-of-your-project] [name-of-your-database] [database-username] [database-password] [s3-access-key-id] [s3-secret-access-key] [s3-bucket-name]
         | 
| 15 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/bkwrapper
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'bkwrapper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            db_type              = ARGV[0]
         | 
| 6 | 
            +
            project_name         = ARGV[1]
         | 
| 7 | 
            +
            database_name        = ARGV[2]
         | 
| 8 | 
            +
            database_username    = ARGV[3]
         | 
| 9 | 
            +
            database_password    = ARGV[4]
         | 
| 10 | 
            +
            s3_access_key_id     = ARGV[5]
         | 
| 11 | 
            +
            s3_secret_access_key = ARGV[6]
         | 
| 12 | 
            +
            s3_bucket_name       = ARGV[7]
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            begin
         | 
| 15 | 
            +
              bkwrapper = Bkwrapper::Base.new(project_name)
         | 
| 16 | 
            +
              db_type = db_type == "mysql" ? "mysql" : "pg"
         | 
| 17 | 
            +
              bkwrapper.send(db_type.to_sym, database_username, database_password, database_name)
         | 
| 18 | 
            +
                .backup_and_send_to_s3(s3_access_key_id, s3_secret_access_key, s3_bucket_name)
         | 
| 19 | 
            +
            ensure
         | 
| 20 | 
            +
              Dir.glob('/var/tmp/*.zip').each { |f| File.delete(f) }
         | 
| 21 | 
            +
            end
         | 
    
        data/bkwrapper.gemspec
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bkwrapper/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name          = 'bkwrapper'
         | 
| 7 | 
            +
              s.version       = Bkwrapper::VERSION
         | 
| 8 | 
            +
              s.platform      = Gem::Platform::RUBY
         | 
| 9 | 
            +
              s.date          = '2015-03-24'
         | 
| 10 | 
            +
              s.summary       = 'Backup your databases and send them to your s3 account'
         | 
| 11 | 
            +
              s.description   = 'A simple wrapper for your database backup commands and s3 api.'
         | 
| 12 | 
            +
              s.authors       = ['Filipe Chagas']
         | 
| 13 | 
            +
              s.email         = 'filipe@ochagas.com'
         | 
| 14 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 15 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 16 | 
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 17 | 
            +
              s.require_paths = ['lib']
         | 
| 18 | 
            +
              s.homepage      = 'https://github.com/filipechagas/bkwrapper'
         | 
| 19 | 
            +
              s.license       = 'MIT'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              s.add_runtime_dependency 'rake', '~> 10.4.2'
         | 
| 22 | 
            +
              s.add_runtime_dependency 'aws-sdk', '~> 2'
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module Bkwrapper
         | 
| 2 | 
            +
              module Backup
         | 
| 3 | 
            +
                class BackupExecutor
         | 
| 4 | 
            +
                  def initialize(backupper)
         | 
| 5 | 
            +
                    @backupper = backupper
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def generate_backup
         | 
| 9 | 
            +
                    generate_backup_file
         | 
| 10 | 
            +
                    generate_compressed_file
         | 
| 11 | 
            +
                    remove_backup_file
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    @backupper.compressed_filename
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  private
         | 
| 17 | 
            +
                    def generate_backup_file
         | 
| 18 | 
            +
                      system_execute @backupper.backup_command
         | 
| 19 | 
            +
                    rescue
         | 
| 20 | 
            +
                      raise "Error generating backup file"
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    def generate_compressed_file
         | 
| 24 | 
            +
                      system_execute @backupper.compress_command
         | 
| 25 | 
            +
                    rescue
         | 
| 26 | 
            +
                      raise "Error generating zip file"
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    def remove_backup_file
         | 
| 30 | 
            +
                      system_execute "rm /var/tmp/#{@backupper.backup_filename}"
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def system_execute command
         | 
| 34 | 
            +
                      result = system command
         | 
| 35 | 
            +
                      raise "Command returned an error" unless result
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require_relative "compressor"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Bkwrapper
         | 
| 4 | 
            +
              module Backup
         | 
| 5 | 
            +
                class MysqlBackupper
         | 
| 6 | 
            +
                  include Compressor
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  attr_reader :project_name, :db_username, :db_password, :db_name
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def initialize(project_name, db_username, db_password, db_name)
         | 
| 11 | 
            +
                    @project_name, @db_username, @db_password, @db_name =
         | 
| 12 | 
            +
                      project_name, db_username, db_password, db_name
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def backup_command
         | 
| 16 | 
            +
                    "mysqldump -u#{db_username} -p#{db_password} #{db_name} > /var/tmp/#{backup_filename}"
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def backup_filename
         | 
| 20 | 
            +
                    "#{prefix}-#{project_name}#{suffix}"
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
                    def prefix
         | 
| 25 | 
            +
                      @date_prefix ||= Time.now.strftime("%Y-%m-%d-%H-%M-%S")
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    def suffix
         | 
| 29 | 
            +
                      ".backup"
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require "bkwrapper/backup/compressor"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Bkwrapper
         | 
| 4 | 
            +
              module Backup
         | 
| 5 | 
            +
                class PgBackupper
         | 
| 6 | 
            +
                  include Compressor
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  attr_reader :project_name, :db_username, :db_password, :db_name
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def initialize(project_name, db_username, db_password, db_name)
         | 
| 11 | 
            +
                    @project_name, @db_username, @db_password, @db_name =
         | 
| 12 | 
            +
                      project_name, db_username, db_password, db_name
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def backup_command
         | 
| 16 | 
            +
                    "PGPASSWORD=#{db_password} pg_dump -U #{db_username} -Fc #{db_name} > /var/tmp/#{backup_filename}"
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def backup_filename
         | 
| 20 | 
            +
                    "#{prefix}-#{project_name}#{suffix}"
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
                    def prefix
         | 
| 25 | 
            +
                      @date_prefix ||= Time.now.strftime("%Y-%m-%d-%H-%M-%S")
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    def suffix
         | 
| 29 | 
            +
                      ".backup"
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            require "bkwrapper/backup/backup_executor"
         | 
| 2 | 
            +
            require "bkwrapper/backup/pg_backupper"
         | 
| 3 | 
            +
            require "bkwrapper/s3/uploader"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Bkwrapper
         | 
| 6 | 
            +
              class Base
         | 
| 7 | 
            +
                def initialize(project_name)
         | 
| 8 | 
            +
                  @project_name = project_name
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def pg(db_username, db_password, db_name)
         | 
| 12 | 
            +
                  @backupper = Bkwrapper::Backup::PgBackupper.new(@project_name, db_username, db_password, db_name)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  self
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def mysql(db_username, db_password, db_name)
         | 
| 18 | 
            +
                  @backupper = Bkwrapper::Backup::MysqlBackupper.new(@project_name, db_username, db_password, db_name)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  self
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def backup_and_send_to_s3(access_key_id, secret_access_key, bucket_name)
         | 
| 24 | 
            +
                  uploader = Bkwrapper::S3::Uploader.new access_key_id, secret_access_key, bucket_name, @project_name
         | 
| 25 | 
            +
                  backup_executor = Bkwrapper::Backup::BackupExecutor.new(@backupper)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  backup_filename = backup_executor.generate_backup
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  backup_filename = "/var/tmp/#{backup_filename}"
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  uploader.upload_file backup_filename
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require "aws-sdk"
         | 
| 2 | 
            +
            module Bkwrapper
         | 
| 3 | 
            +
              module S3
         | 
| 4 | 
            +
                class Uploader
         | 
| 5 | 
            +
                  def initialize(access_key_id, secret_access_key, bucket_name, project_name)
         | 
| 6 | 
            +
                    @bucket_name, @project_name = bucket_name, project_name
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    creds = ::Aws::Credentials.new(access_key_id, secret_access_key)
         | 
| 9 | 
            +
                    @s3 = ::Aws::S3::Client.new(credentials: creds, region:'us-east-1')
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def upload_file(filename)
         | 
| 13 | 
            +
                    file_open = File.open(filename)
         | 
| 14 | 
            +
                    @s3.put_object(body: file_open, bucket: "#{@bucket_name}/#{@project_name}", key: File.basename(filename))
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def buckets_names
         | 
| 18 | 
            +
                    @s3.list_buckets.buckets.map(&:name)
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def create_bucket(bucket_name)
         | 
| 22 | 
            +
                    @s3.create_bucket bucket: bucket_name
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def delete_bucket(bucket_name)
         | 
| 26 | 
            +
                    @s3.delete_bucket bucket: bucket_name
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
    
        data/lib/bkwrapper.rb
    ADDED
    
    
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'minitest/autorun'
         | 
| 2 | 
            +
            require 'minitest/mock'
         | 
| 3 | 
            +
            require "bkwrapper/backup/backup_executor"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Bkwrapper::Backup::BackupExecutor.class_eval do
         | 
| 6 | 
            +
              private
         | 
| 7 | 
            +
                def system command
         | 
| 8 | 
            +
                  true
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            describe Bkwrapper::Backup::BackupExecutor do
         | 
| 13 | 
            +
              let(:backupper) { Minitest::Mock.new }
         | 
| 14 | 
            +
              let(:backup_executor) { Bkwrapper::Backup::BackupExecutor.new backupper }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              before do
         | 
| 17 | 
            +
                backupper.expect :compressed_filename, "compressed_filename"
         | 
| 18 | 
            +
                backupper.expect :backup_command, "backup_command"
         | 
| 19 | 
            +
                backupper.expect :compress_command, "compress_command"
         | 
| 20 | 
            +
                backupper.expect :backup_filename, "backup_filename"
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              it 'should execute the correct chain of commands' do
         | 
| 24 | 
            +
                backup_executor.generate_backup.must_equal "compressed_filename"
         | 
| 25 | 
            +
                backupper.verify
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require 'minitest/autorun'
         | 
| 2 | 
            +
            require "bkwrapper/backup/compressor"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class CompressorHost
         | 
| 5 | 
            +
              include Bkwrapper::Backup::Compressor
         | 
| 6 | 
            +
              def backup_filename
         | 
| 7 | 
            +
                "backupfile"
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            describe CompressorHost do
         | 
| 12 | 
            +
              before do
         | 
| 13 | 
            +
                @compressor = CompressorHost.new
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              it 'should construct zip command properly' do
         | 
| 17 | 
            +
                @compressor.compress_command.must_equal "zip /var/tmp/backupfile.zip /var/tmp/backupfile"
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it 'should define compressed filename properly' do
         | 
| 21 | 
            +
                @compressor.compressed_filename.must_equal "backupfile.zip"
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'minitest/autorun'
         | 
| 2 | 
            +
            require 'minitest/mock'
         | 
| 3 | 
            +
            require "bkwrapper/backup/mysql_backupper"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe Bkwrapper::Backup::MysqlBackupper do
         | 
| 6 | 
            +
              before do
         | 
| 7 | 
            +
                @test_project_name = "testproject"
         | 
| 8 | 
            +
                @db_username = "username"
         | 
| 9 | 
            +
                @db_password = "password"
         | 
| 10 | 
            +
                @db_name = "database"
         | 
| 11 | 
            +
                @backup_filename = "xxx-#{@test_project_name}.backup"
         | 
| 12 | 
            +
                @pg_backupper = Bkwrapper::Backup::MysqlBackupper.new(@test_project_name, @db_username, @db_password, @db_name)
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              it 'should construct the right filename' do
         | 
| 16 | 
            +
                @pg_backupper.stub :prefix, "xxx" do
         | 
| 17 | 
            +
                  @pg_backupper.backup_filename.must_equal @backup_filename
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              it 'should construct command properly' do
         | 
| 22 | 
            +
                @pg_backupper.stub :prefix, "xxx" do
         | 
| 23 | 
            +
                  @pg_backupper.backup_command.
         | 
| 24 | 
            +
                    must_equal "mysqldump -u#{@db_username} -p#{@db_password} #{@db_name} > /var/tmp/#{@backup_filename}"
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'minitest/autorun'
         | 
| 2 | 
            +
            require 'minitest/mock'
         | 
| 3 | 
            +
            require "bkwrapper/backup/pg_backupper"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe Bkwrapper::Backup::PgBackupper do
         | 
| 6 | 
            +
              before do
         | 
| 7 | 
            +
                @test_project_name = "testproject"
         | 
| 8 | 
            +
                @db_username = "username"
         | 
| 9 | 
            +
                @db_password = "password"
         | 
| 10 | 
            +
                @db_name = "database"
         | 
| 11 | 
            +
                @backup_filename = "xxx-#{@test_project_name}.backup"
         | 
| 12 | 
            +
                @pg_backupper = Bkwrapper::Backup::PgBackupper.new(@test_project_name, @db_username, @db_password, @db_name)
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              it 'should construct the right filename' do
         | 
| 16 | 
            +
                @pg_backupper.stub :prefix, "xxx" do
         | 
| 17 | 
            +
                  @pg_backupper.backup_filename.must_equal @backup_filename
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              it 'should construct command properly' do
         | 
| 22 | 
            +
                @pg_backupper.stub :prefix, "xxx" do
         | 
| 23 | 
            +
                  @pg_backupper.backup_command.
         | 
| 24 | 
            +
                    must_equal "PGPASSWORD=#{@db_password} pg_dump -U #{@db_username} -Fc #{@db_name} > /var/tmp/#{@backup_filename}"
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,94 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: bkwrapper
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Filipe Chagas
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-03-24 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rake
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ~>
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 10.4.2
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ~>
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 10.4.2
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: aws-sdk
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ~>
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '2'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ~>
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '2'
         | 
| 41 | 
            +
            description: A simple wrapper for your database backup commands and s3 api.
         | 
| 42 | 
            +
            email: filipe@ochagas.com
         | 
| 43 | 
            +
            executables:
         | 
| 44 | 
            +
            - bkwrapper
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files: []
         | 
| 47 | 
            +
            files:
         | 
| 48 | 
            +
            - Gemfile
         | 
| 49 | 
            +
            - Gemfile.lock
         | 
| 50 | 
            +
            - LICENSE.txt
         | 
| 51 | 
            +
            - README.md
         | 
| 52 | 
            +
            - Rakefile
         | 
| 53 | 
            +
            - bin/bkwrapper
         | 
| 54 | 
            +
            - bkwrapper.gemspec
         | 
| 55 | 
            +
            - lib/bkwrapper.rb
         | 
| 56 | 
            +
            - lib/bkwrapper/backup/backup_executor.rb
         | 
| 57 | 
            +
            - lib/bkwrapper/backup/compressor.rb
         | 
| 58 | 
            +
            - lib/bkwrapper/backup/mysql_backupper.rb
         | 
| 59 | 
            +
            - lib/bkwrapper/backup/pg_backupper.rb
         | 
| 60 | 
            +
            - lib/bkwrapper/base.rb
         | 
| 61 | 
            +
            - lib/bkwrapper/s3/uploader.rb
         | 
| 62 | 
            +
            - spec/bkwrapper/backup/backup_executor_spec.rb
         | 
| 63 | 
            +
            - spec/bkwrapper/backup/compressor_spec.rb
         | 
| 64 | 
            +
            - spec/bkwrapper/backup/mysql_backupper_spec.rb
         | 
| 65 | 
            +
            - spec/bkwrapper/backup/pg_backupper_spec.rb
         | 
| 66 | 
            +
            homepage: https://github.com/filipechagas/bkwrapper
         | 
| 67 | 
            +
            licenses:
         | 
| 68 | 
            +
            - MIT
         | 
| 69 | 
            +
            metadata: {}
         | 
| 70 | 
            +
            post_install_message: 
         | 
| 71 | 
            +
            rdoc_options: []
         | 
| 72 | 
            +
            require_paths:
         | 
| 73 | 
            +
            - lib
         | 
| 74 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 75 | 
            +
              requirements:
         | 
| 76 | 
            +
              - - '>='
         | 
| 77 | 
            +
                - !ruby/object:Gem::Version
         | 
| 78 | 
            +
                  version: '0'
         | 
| 79 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 80 | 
            +
              requirements:
         | 
| 81 | 
            +
              - - '>='
         | 
| 82 | 
            +
                - !ruby/object:Gem::Version
         | 
| 83 | 
            +
                  version: '0'
         | 
| 84 | 
            +
            requirements: []
         | 
| 85 | 
            +
            rubyforge_project: 
         | 
| 86 | 
            +
            rubygems_version: 2.0.14
         | 
| 87 | 
            +
            signing_key: 
         | 
| 88 | 
            +
            specification_version: 4
         | 
| 89 | 
            +
            summary: Backup your databases and send them to your s3 account
         | 
| 90 | 
            +
            test_files:
         | 
| 91 | 
            +
            - spec/bkwrapper/backup/backup_executor_spec.rb
         | 
| 92 | 
            +
            - spec/bkwrapper/backup/compressor_spec.rb
         | 
| 93 | 
            +
            - spec/bkwrapper/backup/mysql_backupper_spec.rb
         | 
| 94 | 
            +
            - spec/bkwrapper/backup/pg_backupper_spec.rb
         |