redis-copy.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # redis-copy.rb - Copyright (C) 2009-2010 Salvatore Sanfilippo
  2. # BSD license, See the COPYING file for more information.
  3. #
  4. # Copy the whole dataset from one Redis instance to another one
  5. #
  6. # WARNING: this utility is deprecated and serves as a legacy adapter
  7. # for the more-robust redis-copy gem.
  8. require 'shellwords'
  9. def redisCopy(opts={})
  10. src = "#{opts[:srchost]}:#{opts[:srcport]}"
  11. dst = "#{opts[:dsthost]}:#{opts[:dstport]}"
  12. `redis-copy #{src.shellescape} #{dst.shellescape}`
  13. rescue Errno::ENOENT
  14. $stderr.puts 'This utility requires the redis-copy executable',
  15. 'from the redis-copy gem on https://rubygems.org',
  16. 'To install it, run `gem install redis-copy`.'
  17. exit 1
  18. end
  19. $stderr.puts "This utility is deprecated. Use the redis-copy gem instead."
  20. if ARGV.length != 4
  21. puts "Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
  22. exit 1
  23. end
  24. puts "WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready."
  25. STDIN.gets
  26. srchost = ARGV[0]
  27. srcport = ARGV[1]
  28. dsthost = ARGV[2]
  29. dstport = ARGV[3]
  30. puts "Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}"
  31. redisCopy(:srchost => srchost, :srcport => srcport.to_i,
  32. :dsthost => dsthost, :dstport => dstport.to_i)