Skip to content

Commit

Permalink
Merge pull request #141 from tsigo/develop
Browse files Browse the repository at this point in the history
Prevent utility_path from overriding `cp` path in Redis
  • Loading branch information
Michael van Rooijen committed Jun 5, 2011
2 parents cfa33d2 + cf806d6 commit 1238e39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/backup/database/redis.rb
Expand Up @@ -85,7 +85,7 @@ def perform!
def invoke_save!
response = run("#{ utility('redis-cli') } #{ credential_options } #{ connectivity_options } #{ additional_options } 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 "Could not invoke the Redis SAVE command. The #{ database } file might not 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
Expand All @@ -98,7 +98,11 @@ def copy!
exit
end

# Temporarily remove a custom `utility_path` setting so that the system
# `cp` utility can be found, then restore the old value just in case.
old_path, self.utility_path = self.utility_path, nil
run("#{ utility(:cp) } '#{ File.join(path, database) }' '#{ File.join(dump_path, database) }'")
self.utility_path = old_path
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/database/redis_spec.rb
Expand Up @@ -51,7 +51,7 @@
end

describe '#credential_options' do
it 'should return the mongo syntax for the credential options' do
it 'should return the redis-cli syntax for the credential options' do
db.credential_options.should == "-a 'secret'"
end
end
Expand All @@ -72,7 +72,7 @@
end

describe '#invoke_save!' do
it 'should return the full mongodump string' do
it 'should return the full redis-cli string' do
db.expects(:utility).with('redis-cli').returns('redis-cli')
db.expects(:run).with("redis-cli -a 'secret' -h 'localhost' -p '123' -s '/redis.sock' --query SAVE")
db.invoke_save!
Expand All @@ -86,6 +86,13 @@
db.expects(:run).with("cp '#{ File.join('/var/lib/redis/db/mydatabase.rdb') }' '#{ File.join(Backup::TMP_PATH, Backup::TRIGGER, 'Redis', 'mydatabase.rdb') }'")
db.copy!
end

it 'should find the cp utility when utility_path is set' do
File.expects(:exist?).returns(true)
db.utility_path = '/usr/local/bin/redis-cli'
db.expects(:run).with { |v| v =~ %r{^/bin/cp .+} }
db.copy!
end
end

describe '#perform!' do
Expand Down

0 comments on commit 1238e39

Please sign in to comment.