Newer
Older
namespace :backup do
desc "Backup Mongo"
require File.join(Rails.root, 'config', 'initializers', '_load_app_config.rb')
require 'cloudfiles'
puts("event=backup status=start type=mongo")
if AppConfig[:cloudfiles_username] && AppConfig[:cloudfiles_api_key]
cf = CloudFiles::Connection.new(:username => AppConfig[:cloudfiles_username], :api_key => AppConfig[:cloudfiles_api_key])
mongo_container = cf.container("Mongo Backup")
tar_name = "mongo_#{Time.now.to_i}.tar"
`tar cfP /tmp/backup/#{tar_name} /tmp/backup/mongo`
file = mongo_container.create_object(tar_name)
if file.write File.open("/tmp/backup/" + tar_name)
puts("event=backup status=success type=mongo")
`rm /tmp/backup/#{tar_name}`
`rm -rf /tmp/backup/mongo/`
puts("event=backup status=failure type=mongo")
else
puts "Cloudfiles username and api key needed"
end
puts("event=backup status=start type=photos")
if AppConfig[:cloudfiles_username] && AppConfig[:cloudfiles_api_key]
cf = CloudFiles::Connection.new(:username => AppConfig[:cloudfiles_username], :api_key => AppConfig[:cloudfiles_api_key])
photo_container = cf.container("Photo Backup")
tar_name = "photos_#{Time.now.to_i}.tar"
`tar cfP /tmp/backup/#{tar_name} /usr/local/app/diaspora/public/uploads/images/`
if file.write File.open("/tmp/backup/" + tar_name)
puts("event=backup status=success type=photos")
puts("event=backup status=failure type=photos")
else
puts "Cloudfiles username and api key needed"
end
end