Skip to content

Instantly share code, notes, and snippets.

@lajunta
Created April 14, 2016 11:12
Show Gist options
  • Save lajunta/901d15757bff9df7bec66a2131792337 to your computer and use it in GitHub Desktop.
Save lajunta/901d15757bff9df7bec66a2131792337 to your computer and use it in GitHub Desktop.
find latest zip and mongorestore it
#!/usr/bin/env ruby
require "tmpdir"
dbpath = "/data/dbback"
file = `find #{dbpath} -type f -printf "%p\n" | sort -rn | head -n 1 `
Dir.mktmpdir do |dir|
`tar -C #{dir} -zxvf #{file} `
basename = File.basename(file,".gz")
rdir =dir+"/"+basename.gsub(".tar.gz","")
`mongorestore --drop --quiet #{rdir}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment