Commit 481204a1 authored by zhitomirskiyi's avatar zhitomirskiyi

mongo cloudfiles backup task

parent 50eb0a92
......@@ -47,6 +47,10 @@ gem 'mini_magick'
gem 'aws'
gem 'fastercsv', :require => false
gem 'jammit'
#Backups
gem "cloudfiles", :require => false
group :test, :development do
gem 'factory_girl_rails'
gem 'ruby-debug19' if RUBY_VERSION.include? "1.9"
......
......@@ -67,6 +67,12 @@ default:
#google analytics key, if false, it won't include the javascript
google_a_site: false
#cloudfiles username and api-key, used for backups
cloudfiles_username: 'example'
cloudfiles_api_key: 'abc123'
development:
test:
......
namespace :backup do
desc "Backup Mongo"
task :mongo do
cf = CloudFiles::Connection.new(:username => "", :api_key => "")
require 'cloudfiles'
if APP_CONFIG[:cloudfiles_username] && APP_CONFIG[:cloudfiles_api_key]
cf = CloudFiles::Connection.new(:username => APP_CONFIG[:cloudfiles_username], :api_key => APP_CONFIG[:cloudfiles_api_key])
mongo_container = cf.container("Mongo Backup")
file = cont.create_object("test.txt")
file.write "Things"
`mongodump -o /tmp/backup/mongo`
tar_name = "mongo_#{Time.now.to_i}.tar"
`tar cfP /tmp/backup/#{tar_name} /tmp/backup/mongo`
file = mongo_container.create_object(tar_name)
success = file.write File.open("/tmp/backup/" + tar_name)
if success
`rm /tmp/backup/#{tar_name}`
`rm -rf /tmp/backup/mongo/`
end
else
puts "Cloudfiles username and api key needed"
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment