Class: Backup::Database::Redis
- Defined in:
- lib/backup/database/redis.rb
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Builds a Redis compatible string for the additional options specified by the user.
-
#host ⇒ Object
Connectivity options.
-
#invoke_save ⇒ Object
Determines whether Backup should invoke the SAVE command through the ‘redis-cli’ utility to persist the most recent data before copying over the dump file.
-
#name ⇒ Object
Name of and path to the database that needs to get dumped.
-
#password ⇒ Object
Credentials for the specified database.
-
#path ⇒ Object
Name of and path to the database that needs to get dumped.
-
#port ⇒ Object
Connectivity options.
-
#socket ⇒ Object
Connectivity options.
Attributes inherited from Base
Instance Method Summary collapse
-
#connectivity_options ⇒ Object
Builds the Redis connectivity options syntax to connect the user to perform the database dumping process.
-
#copy! ⇒ Object
Performs the copy command to copy over the Redis dump file to the Backup archive.
-
#credential_options ⇒ Object
Builds the Redis credentials syntax to authenticate the user to perform the database dumping process.
-
#database ⇒ Object
Returns the Redis database file name.
-
#initialize(&block) ⇒ Redis
constructor
Creates a new instance of the Redis database object.
-
#invoke_save! ⇒ Object
Tells Redis to persist the current state of the in-memory database to the persisted dump file.
-
#perform! ⇒ Object
Performs the Redis backup by using the ‘cp’ unix utility to copy the persisted Redis dump file to the Backup archive.
Methods inherited from Base
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ Redis
Creates a new instance of the Redis database object
31 32 33 34 35 36 37 38 |
# File 'lib/backup/database/redis.rb', line 31 def initialize(&block) load_defaults! @additional_options ||= Array.new instance_eval(&block) prepare! end |
Instance Attribute Details
#additional_options ⇒ Object
Builds a Redis compatible string for the additional options specified by the user
27 28 29 |
# File 'lib/backup/database/redis.rb', line 27 def @additional_options end |
#host ⇒ Object
Connectivity options
23 24 25 |
# File 'lib/backup/database/redis.rb', line 23 def host @host end |
#invoke_save ⇒ Object
Determines whether Backup should invoke the SAVE command through the ‘redis-cli’ utility to persist the most recent data before copying over the dump file
19 20 21 |
# File 'lib/backup/database/redis.rb', line 19 def invoke_save @invoke_save end |
#name ⇒ Object
Name of and path to the database that needs to get dumped
9 10 11 |
# File 'lib/backup/database/redis.rb', line 9 def name @name end |
#password ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/redis.rb', line 13 def password @password end |
#path ⇒ Object
Name of and path to the database that needs to get dumped
9 10 11 |
# File 'lib/backup/database/redis.rb', line 9 def path @path end |
#port ⇒ Object
Connectivity options
23 24 25 |
# File 'lib/backup/database/redis.rb', line 23 def port @port end |
#socket ⇒ Object
Connectivity options
23 24 25 |
# File 'lib/backup/database/redis.rb', line 23 def socket @socket end |
Instance Method Details
#connectivity_options ⇒ Object
Builds the Redis connectivity options syntax to connect the user to perform the database dumping process
50 51 52 53 54 |
# File 'lib/backup/database/redis.rb', line 50 def %w[host port socket].map do |option| next if send(option).nil?; "-#{option[0,1]} '#{send(option)}'" end.compact.join("\s") end |
#copy! ⇒ Object
Performs the copy command to copy over the Redis dump file to the Backup archive
95 96 97 98 99 100 101 102 |
# File 'lib/backup/database/redis.rb', line 95 def copy! unless File.exist?(File.join(path, database)) Logger.error "Redis database dump not found in '#{ File.join(path, database) }'" exit end run("#{ utility(:cp) } '#{ File.join(path, database) }' '#{ File.join(dump_path, database) }'") end |
#credential_options ⇒ Object
Builds the Redis credentials syntax to authenticate the user to perform the database dumping process
43 44 45 |
# File 'lib/backup/database/redis.rb', line 43 def return "-a '#{password}'" if password; String.new end |
#database ⇒ Object
Returns the Redis database file name
65 66 67 |
# File 'lib/backup/database/redis.rb', line 65 def database "#{ name }.rdb" end |
#invoke_save! ⇒ Object
Tells Redis to persist the current state of the in-memory database to the persisted dump file
85 86 87 88 89 90 91 |
# File 'lib/backup/database/redis.rb', line 85 def invoke_save! response = run("#{ utility('redis-cli') } #{ } #{ } #{ } SAVE") unless response =~ /OK/ Logger.error "Could not invoke the Redis SAVE command. The #{ database } file might not be contain the most recent data." Logger.error "Please check if the server is running, the credentials (if any) are correct, and the host/port/socket are correct." end end |
#perform! ⇒ Object
Performs the Redis backup by using the ‘cp’ unix utility to copy the persisted Redis dump file to the Backup archive. Additionally, when ‘invoke_save’ is set to true, it’ll tell the Redis server to persist the current state to the dump file before copying the dump to get the most recent updates in to the backup
75 76 77 78 79 80 |
# File 'lib/backup/database/redis.rb', line 75 def perform! log! invoke_save! if invoke_save copy! end |