Class: Backup::Database::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/database/redis.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

MODES =
[:copy, :sync]

Instance Attribute Summary collapse

Attributes inherited from Base

#database_id, #dump_path, #model

Instance Method Summary collapse

Methods included from Config::Helpers

included

Constructor Details

#initialize(model, database_id = nil, &block) ⇒ Redis

Returns a new instance of Redis.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/backup/database/redis.rb', line 56

def initialize(model, database_id = nil, &block)
  super
  instance_eval(&block) if block_given?

  @mode ||= :copy

  unless MODES.include?(mode)
    raise Error, "'#{ mode }' is not a valid mode"
  end

  if mode == :copy && rdb_path.nil?
    raise Error, '`rdb_path` must be set when `mode` is :copy'
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers

Instance Attribute Details

#additional_optionsObject

Additional options for the redis-cli utility.



54
55
56
# File 'lib/backup/database/redis.rb', line 54

def additional_options
  @additional_options
end

#hostObject

Connectivity options for the redis-cli utility.



46
47
48
# File 'lib/backup/database/redis.rb', line 46

def host
  @host
end

#invoke_saveObject

Perform a SAVE command using the redis-cli utility before copying the dump file specified by #rdb_path.

Only valid when #mode is :copy.



42
43
44
# File 'lib/backup/database/redis.rb', line 42

def invoke_save
  @invoke_save
end

#modeObject

Mode of operation.

:copy

Copies the redis dump file specified by #rdb_path. This data will be current as of the last RDB Snapshot performed by the server (per your redis.conf settings). You may set #invoke_save to true to have Backup issue a SAVE command to update the dump file with the current data before performing the copy.

:sync

Performs a dump of your redis data using redis-cli –rdb -. Redis implements this internally using a SYNC command. The operation is analogous to requesting a BGSAVE, then having the dump returned. This mode is capable of dumping data from a local or remote server. Requires Redis v2.6 or better.

Defaults to :copy.



29
30
31
# File 'lib/backup/database/redis.rb', line 29

def mode
  @mode
end

#passwordObject

Password for the redis-cli utility.



50
51
52
# File 'lib/backup/database/redis.rb', line 50

def password
  @password
end

#portObject

Connectivity options for the redis-cli utility.



46
47
48
# File 'lib/backup/database/redis.rb', line 46

def port
  @port
end

#rdb_pathObject

Full path to the redis dump file.

Required when #mode is :copy.



35
36
37
# File 'lib/backup/database/redis.rb', line 35

def rdb_path
  @rdb_path
end

#socketObject

Connectivity options for the redis-cli utility.



46
47
48
# File 'lib/backup/database/redis.rb', line 46

def socket
  @socket
end

Instance Method Details

#perform!Object

Performs the dump based on #mode and stores the Redis dump file to the dump_path using the dump_filename.

<trigger>/databases/Redis[-<database_id>].rdb[.gz]


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/backup/database/redis.rb', line 76

def perform!
  super

  case mode
  when :sync
    # messages output by `redis-cli --rdb` on $stderr
    Logger.configure do
      ignore_warning(/Transfer finished with success/)
      ignore_warning(/SYNC sent to master/)
    end
    sync!
  when :copy
    save! if invoke_save
    copy!
  end

  log!(:finished)
end