lib/dumpr/driver.rb
# creates @dumpfile
# pipes :dump_cmd to gzip, rather than write the file to disk twice
# if @destination is defined, it then moves the dump to the @destination, which can be a remote host:path
creates @dumpfile
pipes :dump_cmd to gzip, rather than write the file to disk twice
if @destination is defined, it then moves the dump to the @destination, which can be a remote host:path
creates @dumpfile pipes : dump_cmd to gzip rather than write the file to disk twice if @destination is defined it then moves the dump to the @destination which can be a remote host : path
def dump
        logger.debug("begin dump")
        if dump_installed? != true
          raise MissingDriver.new "#{self.class} does not appear to be installed.\nCould not find command `#{dump_cmd.to_s.split.first}`"
        end
        dumpfn = @dumpfile + (@gzip ? ".gz" : "")
        Util.with_lockfile("localhost", dumpfn, @opts[:force]) do
          logger.debug "preparing dump..."
          if !File.exists?(File.dirname(dumpfn))
            run "mkdir -p #{File.dirname(dumpfn)}"
          end
          if File.exists?(dumpfn)
            if @opts[:force]
              logger.warn "#{dumpfn} exists, moving it to #{dumpfn}.1"
              run "mv #{dumpfn} #{dumpfn}.1"
            else
              logger.warn "#{dumpfn} already exists!"
              raise DumpFileExists.new "#{dumpfn} already exists!"
            end
          end
          logger.debug "dumping..."
          if @gzip
            run "#{dump_cmd} | gzip #{gzip_options} > #{dumpfn}"
          else
            run "#{dump_cmd} > #{dumpfn}"
          end
          dumpsize = Util.human_file_size("localhost", dumpfn)
          logger.info("generated #{dumpfn} (#{dumpsize})")
          if @destination
            if remote_destination?
              logger.debug "exporting to #{@destination_host}..."
              Util.with_lockfile(@destination_host, @destination_dumpfile, @opts[:force]) do
                run "scp #{dumpfn} #{@destination_host}:#{@destination_dumpfile}#{@gzip ? '.gz' : ''}"
              end
            elsif @destination_dumpfile && @destination_dumpfile+(@gzip ? '.gz' : '') != dumpfn
              logger.debug "exporting..."
              destdir = File.dirname(@destination_dumpfile)
              run "mkdir -p #{destdir}" if !Util.dir_exists?("localhost", destdir)
              Util.with_lockfile("localhost", @destination_dumpfile, @opts[:force]) do
                run "mv #{dumpfn} #{@destination_dumpfile}#{@gzip ? '.gz' : ''}"
              end
            end
          end
        end 
        logger.debug("end dump")
      end
def dump logger . debug ( "begin dump" ) if dump_installed? != true raise MissingDriver . new "#{self.class} does not appear to be installed.\nCould not find command `#{dump_cmd.to_s.split.first}`" end dumpfn = @dumpfile + ( @gzip ? ".gz" : "" ) Util . with_lockfile ( "localhost" , dumpfn , @opts [ :force ] ) do logger . debug "preparing dump..." if ! File . exists? ( File . dirname ( dumpfn ) ) run "mkdir -p #{File.dirname(dumpfn)}" end if File . exists? ( dumpfn ) if @opts [ :force ] logger . warn "#{dumpfn} exists, moving it to #{dumpfn}.1" run "mv #{dumpfn} #{dumpfn}.1" else logger . warn "#{dumpfn} already exists!" raise DumpFileExists . new "#{dumpfn} already exists!" end end logger . debug "dumping..." if @gzip run "#{dump_cmd} | gzip #{gzip_options} > #{dumpfn}" else run "#{dump_cmd} > #{dumpfn}" end dumpsize = Util . human_file_size ( "localhost" , dumpfn ) logger . info ( "generated #{dumpfn} (#{dumpsize})" ) if @destination if remote_destination? logger . debug "exporting to #{@destination_host}..." Util . with_lockfile ( @destination_host , @destination_dumpfile , @opts [ :force ] ) do run "scp #{dumpfn} #{@destination_host}:#{@destination_dumpfile}#{@gzip ? '.gz' : ''}" end elsif @destination_dumpfile && @destination_dumpfile + ( @gzip ? '.gz' : '' ) != dumpfn logger . debug "exporting..." destdir = File . dirname ( @destination_dumpfile ) run "mkdir -p #{destdir}" if ! Util . dir_exists? ( "localhost" , destdir ) Util . with_lockfile ( "localhost" , @destination_dumpfile , @opts [ :force ] ) do run "mv #{dumpfn} #{@destination_dumpfile}#{@gzip ? '.gz' : ''}" end end end end logger . debug ( "end dump" ) end
creates @dumpfile
pipes :dump_cmd to gzip, rather than write the file to disk twice
if @destination is defined, it then moves the dump to the @destination, which can be a remote host:path
creates @dumpfile pipes : dump_cmd to gzip rather than write the file to disk twice if @destination is defined it then moves the dump to the @destination which can be a remote host : path
# avoid overwriting dump files.. #run "rm -f #{dumpfn}.1;" # with_lockfile