sqlup 0.0.12 → 0.0.13
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.
- data/History.txt +7 -0
- data/Rakefile +1 -1
- data/bin/sqlup +34 -25
- data/lib/mysql_backup.rb +2 -2
- data/lib/mysql_backup/librarian.rb +2 -0
- data/lib/mysql_backup/librarian/backup.rb +0 -1
- data/test/unit/mysql_backup/librarian/librarian_test.rb +2 -3
- metadata +2 -2
    
        data/History.txt
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -12,7 +12,7 @@ Hoe.new('sqlup', MysqlBackup::VERSION) do |p| | |
| 12 12 | 
             
              p.extra_deps << ['optiflag', '>= 0.6.5']
         | 
| 13 13 | 
             
              p.extra_deps << ['daemons', '>= 1.0.6']
         | 
| 14 14 | 
             
              p.extra_deps << ['aws-s3', '>= 0.3.0']
         | 
| 15 | 
            -
              p.extra_deps << ' | 
| 15 | 
            +
              p.extra_deps << 'activerecord'
         | 
| 16 16 | 
             
              p.remote_rdoc_dir = ''
         | 
| 17 17 | 
             
            end
         | 
| 18 18 |  | 
    
        data/bin/sqlup
    CHANGED
    
    | @@ -5,7 +5,9 @@ require 'rubygems' | |
| 5 5 | 
             
            require 'optiflag'
         | 
| 6 6 | 
             
            require 'pp'
         | 
| 7 7 | 
             
            require 'logger'
         | 
| 8 | 
            -
            require 'active_record'
         | 
| 8 | 
            +
            require 'active_record/vendor/mysql'
         | 
| 9 | 
            +
            require 'ostruct'
         | 
| 10 | 
            +
             | 
| 9 11 | 
             
            require File.dirname(__FILE__) + '/../lib/mysql_backup'
         | 
| 10 12 |  | 
| 11 13 | 
             
            module Example extend OptiFlagSet
         | 
| @@ -25,56 +27,63 @@ module Example extend OptiFlagSet | |
| 25 27 | 
             
              optional_flag "engine", :description => "The storage engine.  The default (and currently the only option) is s3."
         | 
| 26 28 | 
             
              optional_flag "get_directory", :alternate_forms => 'd', :description => "The directory to write files for the get command (defaults to the current directory)"
         | 
| 27 29 | 
             
              optional_flag 'logs_delay', :description => 'The delay (in seconds, as a float) to use for log_daemon.  Defaults to 1.'
         | 
| 30 | 
            +
              optional_flag 'config', :description => 'The location of the .sqluprc file to use (instead of ENV[HOME]/.sqluprc)'
         | 
| 31 | 
            +
              optional_flag 'user', :description => 'The mysql user'
         | 
| 32 | 
            +
              optional_flag 'pass', :description => 'The mysql password'
         | 
| 33 | 
            +
              optional_flag 'user', :description => 'The mysql socket'
         | 
| 28 34 | 
             
              optional_switch_flag 'verbose', :alternate_forms => %w(v) do
         | 
| 29 35 | 
             
                description 'Send verbose output'
         | 
| 30 36 | 
             
              end
         | 
| 31 37 | 
             
              and_process!
         | 
| 32 38 | 
             
            end 
         | 
| 33 39 |  | 
| 34 | 
            -
            flags = ARGV.flags
         | 
| 40 | 
            +
            flags = OpenStruct.new ARGV.flags
         | 
| 35 41 |  | 
| 36 | 
            -
            if flags.help | 
| 42 | 
            +
            if flags.help
         | 
| 37 43 | 
             
              puts File.readlines(File.dirname(__FILE__) + '/../README.txt')
         | 
| 38 44 | 
             
              exit 0
         | 
| 39 45 | 
             
            end
         | 
| 40 46 |  | 
| 41 | 
            -
            puts "Warning: no -bucket specified" unless flags.bucket | 
| 47 | 
            +
            puts "Warning: no -bucket specified" unless flags.bucket
         | 
| 42 48 |  | 
| 43 49 | 
             
            if flags.get && !flags.name
         | 
| 44 50 | 
             
              raise RuntimeError, "You must specify the name of a backup (--name)"
         | 
| 45 51 | 
             
            end
         | 
| 46 52 |  | 
| 47 | 
            -
            if flags.verbose | 
| 53 | 
            +
            if flags.verbose
         | 
| 48 54 | 
             
              log = Logger.new $stderr
         | 
| 49 55 | 
             
              log.level = Logger::DEBUG
         | 
| 50 56 | 
             
            else
         | 
| 51 57 | 
             
              log = nil
         | 
| 52 58 | 
             
            end
         | 
| 53 59 |  | 
| 60 | 
            +
            # Read in more flags from the .sqluprc config file
         | 
| 61 | 
            +
            flags.config ||= (Pathname.new(ENV['HOME'] || '/') + '.sqluprc').cleanpath
         | 
| 62 | 
            +
            p = Pathname.new flags.config
         | 
| 63 | 
            +
            if p.readable?
         | 
| 64 | 
            +
              keys = YAML::load p.open
         | 
| 65 | 
            +
              keys.each_pair do |k,v|
         | 
| 66 | 
            +
                flags.send "#{k}=", v
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            else
         | 
| 69 | 
            +
              raise RuntimeError, ("Cannot open #{p.to_s}; that file should have two lines, one for access_key_id: yourkey and the other for secret_access_key: yourotherkey")
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
             | 
| 54 72 | 
             
            engine = flags.engine || 's3'
         | 
| 55 73 |  | 
| 56 74 | 
             
            case engine
         | 
| 57 75 | 
             
            when 's3'
         | 
| 58 76 | 
             
              # Read the keys from the $HOME/.sqluprc file
         | 
| 59 | 
            -
              args = {:log => log, :bucket => flags.bucket}
         | 
| 60 | 
            -
              p = Pathname.new(ENV['HOME']) + '.sqluprc'
         | 
| 61 | 
            -
              if p.readable?
         | 
| 62 | 
            -
                keys = YAML::load p.open
         | 
| 63 | 
            -
                keys.each_pair do |k,v|
         | 
| 64 | 
            -
                  args[k.to_sym] = v
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
              else
         | 
| 67 | 
            -
                raise RuntimeError, ("Cannot open #{p.to_s}; that file should have two lines, one for access_key_id: yourkey and the other for secret_access_key: yourotherkey")
         | 
| 68 | 
            -
              end
         | 
| 77 | 
            +
              args = {:log => log, :bucket => flags.bucket, :access_key_id => flags.access_key_id, :secret_access_key => flags.secret_access_key}
         | 
| 69 78 | 
             
              engine = MysqlBackup::Storage::S3.new args
         | 
| 70 79 | 
             
              engine.read_existing_objects
         | 
| 71 80 | 
             
            end
         | 
| 72 | 
            -
            librarian = MysqlBackup::Librarian.new :log => log, :storage => engine, :user =>  | 
| 81 | 
            +
            librarian = MysqlBackup::Librarian.new :log => log, :storage => engine, :bucket => flags.bucket, :user => flags.user, :pass => flags.pass, :sock => flags.sock
         | 
| 73 82 |  | 
| 74 83 | 
             
            begin
         | 
| 75 | 
            -
              if flags.ls | 
| 84 | 
            +
              if flags.ls
         | 
| 76 85 | 
             
                klass = Kernel.const_get flags.backup_type rescue nil
         | 
| 77 | 
            -
             | 
| 86 | 
            +
                klass ||= case flags.backup_type
         | 
| 78 87 | 
             
                when /log_complete/: MysqlBackup::Librarian::Backup::Log::Complete
         | 
| 79 88 | 
             
                when /log_current/: MysqlBackup::Librarian::Backup::Log::Current
         | 
| 80 89 | 
             
                when /log/: MysqlBackup::Librarian::Backup::Log
         | 
| @@ -86,25 +95,25 @@ begin | |
| 86 95 | 
             
                end
         | 
| 87 96 | 
             
                puts librarian.ls(klass).slice(range).join("\n")
         | 
| 88 97 | 
             
              end
         | 
| 89 | 
            -
              if flags.mysqldump | 
| 98 | 
            +
              if flags.mysqldump
         | 
| 90 99 | 
             
                librarian.backup_mysqldump
         | 
| 91 100 | 
             
              end
         | 
| 92 | 
            -
              if flags.binary | 
| 101 | 
            +
              if flags.binary
         | 
| 93 102 | 
             
                librarian.backup_data_files
         | 
| 94 103 | 
             
              end
         | 
| 95 | 
            -
              if flags.rm | 
| 104 | 
            +
              if flags.rm
         | 
| 96 105 | 
             
                librarian.rm flags.name
         | 
| 97 106 | 
             
              end
         | 
| 98 | 
            -
              if flags.logs | 
| 107 | 
            +
              if flags.logs
         | 
| 99 108 | 
             
                librarian.backup_binary_logs
         | 
| 100 109 | 
             
              end
         | 
| 101 | 
            -
              if flags.get | 
| 110 | 
            +
              if flags.get
         | 
| 102 111 | 
             
                librarian.get flags.name, flags.get_directory || '.'
         | 
| 103 112 | 
             
              end
         | 
| 104 | 
            -
              if flags.get_logs | 
| 113 | 
            +
              if flags.get_logs
         | 
| 105 114 | 
             
                librarian.get_logs flags.get_directory || '.'
         | 
| 106 115 | 
             
              end
         | 
| 107 | 
            -
              if flags.log_daemon | 
| 116 | 
            +
              if flags.log_daemon
         | 
| 108 117 | 
             
                while true
         | 
| 109 118 | 
             
                  librarian.backup_binary_logs
         | 
| 110 119 | 
             
                  delay = flags.logs_delay.to_f
         | 
    
        data/lib/mysql_backup.rb
    CHANGED
    
    | @@ -1,10 +1,10 @@ | |
| 1 1 | 
             
            $:.unshift File.dirname(__FILE__)
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'rubygems'
         | 
| 4 | 
            -
            require 'active_record'
         | 
| 4 | 
            +
            require 'active_record/vendor/mysql'
         | 
| 5 5 | 
             
            require 'mysql_backup/librarian'
         | 
| 6 6 | 
             
            require 'mysql_backup/storage/s3'
         | 
| 7 7 |  | 
| 8 8 | 
             
            module MysqlBackup
         | 
| 9 | 
            -
              VERSION = '0.0. | 
| 9 | 
            +
              VERSION = '0.0.13'
         | 
| 10 10 | 
             
            end
         | 
| @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'rubygems'
         | 
| 2 | 
            +
            require 'active_record/vendor/mysql'
         | 
| 2 3 | 
             
            require 'named_arguments'
         | 
| 3 4 | 
             
            require 'mysql_backup/server'
         | 
| 4 5 | 
             
            require 'mysql_backup/storage/s3'
         | 
| @@ -170,6 +171,7 @@ class MysqlBackup::Librarian | |
| 170 171 | 
             
              end
         | 
| 171 172 |  | 
| 172 173 | 
             
              def create_connection 
         | 
| 174 | 
            +
                ENV["MYSQL_UNIX_PORT"] ||= '/var/lib/mysql/mysql.sock'
         | 
| 173 175 | 
             
                @connection ||= Mysql.connect(@host, @user, @pass, @db, @port, @sock, @flag)
         | 
| 174 176 | 
             
              end
         | 
| 175 177 | 
             
            end
         | 
| @@ -75,9 +75,8 @@ class MysqlBackup::LibrarianTest < Test::Unit::TestCase | |
| 75 75 |  | 
| 76 76 | 
             
              def stubbed_librarian
         | 
| 77 77 | 
             
                connection_stub = stub_everything('connection stub')
         | 
| 78 | 
            -
                 | 
| 79 | 
            -
             | 
| 80 | 
            -
                end
         | 
| 78 | 
            +
                MysqlBackup::Librarian.any_instance.stubs(:create_connection).returns(connection_stub)
         | 
| 79 | 
            +
                m = MysqlBackup::Librarian.new :bucket => 'foo', :access_key_id => 'key', :secret_access_key => 'secret_key'
         | 
| 81 80 | 
             
                m.mysql_server.stubs(:show_master_status).returns(:file => 'foo.0001', :position => 10)
         | 
| 82 81 | 
             
                m.mysql_server.stubs(:datadir).returns('/tmp')
         | 
| 83 82 | 
             
                m.mysql_server.stubs(:innodb_data_home_dir).returns('/tmp')
         | 
    
        metadata
    CHANGED
    
    | @@ -3,7 +3,7 @@ rubygems_version: 0.9.4 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: sqlup
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.0. | 
| 6 | 
            +
              version: 0.0.13
         | 
| 7 7 | 
             
            date: 2007-07-23 00:00:00 -07:00
         | 
| 8 8 | 
             
            summary: A backup tool for saving MySQL data to Amazon's S3 service
         | 
| 9 9 | 
             
            require_paths: 
         | 
| @@ -124,7 +124,7 @@ dependencies: | |
| 124 124 | 
             
                    version: 0.3.0
         | 
| 125 125 | 
             
                version: 
         | 
| 126 126 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 127 | 
            -
              name:  | 
| 127 | 
            +
              name: activerecord
         | 
| 128 128 | 
             
              version_requirement: 
         | 
| 129 129 | 
             
              version_requirements: !ruby/object:Gem::Version::Requirement 
         | 
| 130 130 | 
             
                requirements: 
         |