Created
May 23, 2014 02:47
-
-
Save ifyouseewendy/8b6419b548e3afdcf0f3 to your computer and use it in GitHub Desktop.
A basic script to integrate `mongodump` and `mongorestore`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'date' | |
require 'fileutils' | |
app_key = '' | |
DUMP_HOST = 'localhost' | |
DUMP_PORT = '27017' | |
RESTORE_HOST = 'localhost' | |
RESTORE_PORT = '27017' | |
FileUtils.remove_dir("./dump", true) | |
ms = `date -j -f "%Y-%m-%d %H:%M:%S" "#{Date.today.to_s} 00:00:00" "+%s"`.strip + '000' | |
puts "--> Date: #{Date.today}" | |
puts "\n--> mongodump start" | |
str = %Q(mongodump --host #{DUMP_HOST}:#{DUMP_PORT} --db error_type --collection error_types --query '{app_id: ObjectId("#{app_key}"), updated_at: { $gte: Date(#{ms}) } }') | |
system(str) | |
puts "\n--> mongorestore start" | |
`mongorestore --host #{RESTORE_HOST}:#{RESTORE_PORT} --db error_type --collection error_types ./dump/error_type/error_types.bson` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment