#!/usr/bin/ruby # # pdumpfs-rsync: remote pdumpfs using rsync # # Usage: # pdumpfs-rsync @: \ # # # Copyright(C) 2003 Taku YASUI , All rights reserved. # This software uses codes from pdumpfs. pdumpfs is copyrighted by # Satoru Takabayashi . # This is free software with ABSOLUTELY NO WARRANTY. # # You can redistribute it and/or modify it under the terms of # the GNU General Public License version 2. # load '/usr/bin/pdumpfs' require 'ftools' require 'getoptlong' def parse_options ret = [] options = {} rsync_options = [] parser = GetoptLong.new parser.set_options(['--exclude', GetoptLong::REQUIRED_ARGUMENT], ['--exclude-from', GetoptLong::REQUIRED_ARGUMENT], ['--include', GetoptLong::REQUIRED_ARGUMENT], ['--include-from', GetoptLong::REQUIRED_ARGUMENT], ['--base', GetoptLong::REQUIRED_ARGUMENT]) parser.each_option do |name, arg| if ( /^--(in|ex)clude(-from)?/ =~ name) rsync_options.push(sprintf("%s=%s", name, arg)) else options[name.sub(/^--/, "")] = arg end end options['rsync_options'] = rsync_options usage if ARGV[0] == nil || ARGV[1] == nil options['base'] = options['base'] || File.basename(ARGV[0].sub(%r!^[^/]+?:!, '').sub(%r!/+$!, '')) ret.push(File.join(ARGV[1], 'latest', options['base'])) ret.push(ARGV[1]) ret.push(options) end def main src, dest, opts = parse_options rsync_array = ['/usr/bin/rsync', '-avH', '--delete', '--delete-excluded', '--size-only', '--exclude=lost+found/', '--rsh=/usr/bin/ssh'] base = opts['base'] latest = latest_snapshot(src, dest, base) today = File.join(dest, datedir(Date.today), base) rsync_array = rsync_array + opts['rsync_options'] rsync_array.push(ARGV[0].sub(%r!/+$!, '') + '/') rsync_array.push(src + '/') File.umask(0077) File.mkpath(src) File.mkpath(today) if ( system(*rsync_array) ) update_snapshot(src, src, today) else STDERR.print "rsync failed: #{ARGV[0]}\n" exit 100 end end main if __FILE__ == $0