Just to close this thread with a working solution: I did it using a short
ruby script, cause i didn't found a solution using bacula. Here's the
script, feel free to use it or report errors :-)
#!/usr/bin/ruby
require "ftools"
#modify this to your needs: files2backup is a list of directories or files
which should be backed up
files2Backup=[ '/backups/vip/', '/backups/od/' ]
#modify this to your needs: backupDestinations is a list of objects
describing a backup destination.
#path and size should be modified, mounted should always have the value
false, this is used later for error handling
backupDestinations=[ {:path=>'/backups/external/ext_bu_1/',
:size=>927448544000, :mounted=>false },
{:path=>'/backups/external/ext_bu_1/', :size=>927448544000, :mounted=>false
} ]
#Lists all Files of a directory or the file it self if the path parameter
points to a file
#Param. path: The path to the file or directory
#Return an array of hashMaps containing the keys 'path' and 'size'
def getDirContents path
return [ {:path=>path, :size=>File.size(path) }] if File.ftype(path) ==
'file'
return [] if File.ftype(path) != 'directory' || File.basename(path)=='.'
|| File.basename(path)=='..'
return Dir.entries(path).collect{|dirEntry| getDirContents(path + '/' +
dirEntry)}.flatten
end
#prints out debug information and exits
def handleError sortedFileList, backupDestinations, message, exitError=true,
exception=nil
puts "An error occured! Message:"
puts message
puts exception if exception
puts "sorted list of files to backup"
puts sortedFileList
puts "backup destinations"
puts backupDestinations
exit 1 if exitError
end
sortedFileList=files2Backup.collect{|dirOrFileEntry|
getDirContents(dirOrFileEntry)}.flatten.sort{|a,b| b[:size]<=>a[:size]}
backupDestinations.each{|backupDestination|
handleError(sortedFileList, backupDestinations, "Error mounting backup
destination" + backupDestination.to_s) if ! system("mount
", backupDestination[:path])
handleError(sortedFileList, backupDestinations, "Error cleaning backup
destination" + backupDestination.to_s) if ! system("rm",
"-rf", backupDestination[:path] + '/*')
backupDestination[:mounted] = true
sortedFileList.delete_if{|file2Backup|
if (file2Backup[:size] < backupDestination[:size]) then
begin
dstDir=backupDestination[:path] + '/' +
File.dirname(file2Backup[:path])
handleError(sortedFileList, backupDestinations, "Error
creating directory " + dstDir, false) if ! system('mkdir', "-
p", dstDir)
File.copy(file2Backup[:path], backupDestination[:path] + '/'
+ file2Backup[:path])
backupDestination[:size]-=file2Backup[:size]
true
rescue Exception=>e
handleError(sortedFileList, backupDestinations, "Error
copying file: " + file2Backup.to_s, false, e)
end
else
false
end
}
}
handleError(sortedFileList, backupDestinations, "We ran out of backup space,
not all files have been backed up!", false) if ! sorted
FileList.empty?
backupDestinations.each{|backupDestination|
handleError(sortedFileList, backupDestinations, "Could not umount
backupDestination " + backupDestination.to_s, false) if ba
ckupDestination[:mounted] && ! system("umount", backupDestination[:path])
}
exit 0
--
View this message in context:
http://www.nabble.com/backup-1%2C4TB-to-two-usb-1TB-disks-tp17670811p18000451.html
Sent from the Bacula - Users mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
|