mongo cloudfiles backup task
This commit is contained in:
parent
50eb0a9242
commit
481204a157
3 changed files with 27 additions and 3 deletions
4
Gemfile
4
Gemfile
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,23 @@
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue