Skip to content

Instantly share code, notes, and snippets.

@adammiribyan
Created January 26, 2011 21:51
Show Gist options
  • Save adammiribyan/797551 to your computer and use it in GitHub Desktop.
Save adammiribyan/797551 to your computer and use it in GitHub Desktop.
backup of photos with rackrales cloud files
namespace :backup do
require File.join(Rails.root, 'config', 'initializers', '_load_app_config.rb')
require 'cloudfiles'
task :photos do
puts("event=backup status=start type=photos")
if AppConfig[:cloudfiles_username] && AppConfig[:cloudfiles_api_key]
puts "Logging into Cloud Files"
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 /dev/stdout /usr/local/app/diaspora/public/uploads/images/ | split -d -b 4831838208 - /tmp/backup/#{tar_name}`
(0..99).each do |n|
padded_str = n.to_s.rjust(2,'0')
file = photo_container.create_object(tar_name + padded_str)
file_path = "/tmp/backup/" + tar_name + padded_str
if File.exists?(file_path)
if file.write File.open(file_path)
puts("event=backup status=success type=photos")
else
puts("event=backup status=failure type=photos")
end
`rm #{file_path}`
end
end
else
puts "Cloudfiles username and api key needed"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment