Created
February 13, 2013 12:19
-
-
Save pixie79/4944211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This script downloads the current backup from Rackspace Cloud file storage as made by the too cloud script and mounts the raw disk image checking the contents of the /var/log/date file for validity of the current date. (which was created by an hourly cronjob on the live running guest before the backup was taken). | |
require 'rubygems' | |
require 'cloudfiles' | |
guest = ARGV[0] | |
path = ARGV[1] ||= "/opt/dump" | |
container = ARGV[2] ||= "eudc" | |
def check_file(path, filename) | |
system("cat #{path}/#{filename}* >> #{path}/#{filename}.gz") | |
puts "SHA1SUM of compressed backup: " | |
system("sha1sum #{path}/#{filename}.gz") | |
system("gunzip #{path}/#{filename}.gz") | |
system("/sbin/losetup -o 1048576 /dev/loop5 #{path}/#{filename}") | |
system("/bin/mount /dev/loop5 /mnt -t ext4 -o defaults,noatime,nodiratime,ro,errors=remount-ro") | |
if File.exists?("/mnt/var/log/date") | |
puts "\n\nBackup from: " | |
system("cat /mnt/var/log/date\n") | |
else | |
puts "\n\nBackup Error - Check download files\n" | |
end | |
system("/bin/umount /dev/loop5") | |
system("/sbin/losetup -d /dev/loop5") | |
# system("rm -rf #{path}/#{filename}*") | |
end | |
def list_file(guest, container, cf, path) | |
cfcontainer = cf.container("#{container}") | |
cloud_files = cfcontainer.objects | |
cloud_list = Array.new() | |
cloud_day = String.new() | |
cloud_files.each do |cloud_file| | |
if cloud_file =~ /#{guest}/ | |
puts "Matched: #{cloud_file}" | |
cloud_list.push(cloud_file) | |
end | |
end | |
unless cloud_list.empty? | |
cloud_list.each do |list_file| | |
if list_file =~ /\.00/ | |
cloud_day = "#{list_file.split('.')[0]}.#{list_file.split('.')[1]}" | |
puts "Found 00 file for backup set: #{cloud_day}" | |
end | |
end | |
cloud_list.each do |list_file| | |
if list_file =~ /#{cloud_day}/ | |
puts "Collecting File from rackspace: #{list_file}" | |
cmd = "curl -o #{path}/#{list_file} -H 'X-Auth-Token: #{cf.authtoken}' https://#{cf.storagehost}/v1/MossoCloudFS_d6b9d71d-fd4c-44d6-9a7e-6578cad25d3a/#{container}/#{list_file}" | |
system(cmd) | |
end | |
end | |
check_file(path, cloud_day) | |
end | |
end | |
if !(guest) | |
puts "No guest code entered" | |
exit 1 | |
end | |
unless File.directory?(path) | |
puts "Dump Directory #{path} does not exist!" | |
exit 1 | |
end | |
cf = CloudFiles::Connection.new(:username => "XXXXXX", :api_key => "XXXXXXXXX", :auth_url => CloudFiles::AUTH_UK) | |
list_file(guest, container, cf, path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment