xref: /redis-3.2.3/utils/redis-copy.rb (revision ae8642fb)
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
9require 'shellwords'
10
11def redisCopy(opts={})
12  src = "#{opts[:srchost]}:#{opts[:srcport]}"
13  dst = "#{opts[:dsthost]}:#{opts[:dstport]}"
14  `redis-copy #{src.shellescape} #{dst.shellescape}`
15rescue Errno::ENOENT
16  $stderr.puts 'This utility requires the redis-copy executable',
17               'from the redis-copy gem on https://rubygems.org',
18               'To install it, run `gem install redis-copy`.'
19  exit 1
20end
21
22$stderr.puts "This utility is deprecated. Use the redis-copy gem instead."
23if ARGV.length != 4
24    puts "Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
25    exit 1
26end
27puts "WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready."
28STDIN.gets
29srchost = ARGV[0]
30srcport = ARGV[1]
31dsthost = ARGV[2]
32dstport = ARGV[3]
33puts "Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}"
34redisCopy(:srchost => srchost, :srcport => srcport.to_i,
35          :dsthost => dsthost, :dstport => dstport.to_i)
36