Class: Backup::Database::Redis
- Defined in:
- lib/backup/database/redis.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MODES =
[:copy, :sync]
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional options for the
redis-cli
utility. -
#host ⇒ Object
Connectivity options for the
redis-cli
utility. -
#invoke_save ⇒ Object
Perform a
SAVE
command using theredis-cli
utility before copying the dump file specified by #rdb_path. -
#mode ⇒ Object
Mode of operation.
-
#password ⇒ Object
Password for the
redis-cli
utility. -
#port ⇒ Object
Connectivity options for the
redis-cli
utility. -
#rdb_path ⇒ Object
Full path to the redis dump file.
-
#socket ⇒ Object
Connectivity options for the
redis-cli
utility.
Attributes inherited from Base
#database_id, #dump_path, #model
Instance Method Summary collapse
-
#initialize(model, database_id = nil, &block) ⇒ Redis
constructor
A new instance of Redis.
-
#perform! ⇒ Object
Performs the dump based on #mode and stores the Redis dump file to the
dump_path
using thedump_filename
.
Methods included from Config::Helpers
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_options ⇒ Object
Additional options for the redis-cli
utility.
54 55 56 |
# File 'lib/backup/database/redis.rb', line 54 def @additional_options end |
#host ⇒ Object
Connectivity options for the redis-cli
utility.
46 47 48 |
# File 'lib/backup/database/redis.rb', line 46 def host @host end |
#invoke_save ⇒ Object
42 43 44 |
# File 'lib/backup/database/redis.rb', line 42 def invoke_save @invoke_save end |
#mode ⇒ Object
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 aSAVE
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 aBGSAVE
, 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 |
#password ⇒ Object
Password for the redis-cli
utility.
50 51 52 |
# File 'lib/backup/database/redis.rb', line 50 def password @password end |
#port ⇒ Object
Connectivity options for the redis-cli
utility.
46 47 48 |
# File 'lib/backup/database/redis.rb', line 46 def port @port end |
#rdb_path ⇒ Object
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 |
#socket ⇒ Object
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 |