Sha256: 42e0602ba669ff044534ff252f48593264f228ce98de5378f3cd8987c59029ac

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Backup
  module Database
    class SQLite < Base
      class Error < Backup::Error; end

      ##
      # Path to the sqlite3 file
      attr_accessor :path

      ##
      # Path to sqlite utility (optional)
      attr_accessor :sqlitedump_utility

      ##
      # Creates a new instance of the SQLite adapter object
      def initialize(model, database_id = nil, &block)
        super
        instance_eval(&block) if block_given?

        @sqlitedump_utility ||= utility(:sqlitedump)
      end

      ##
      # Performs the sqlitedump command and outputs the
      # data to the specified path based on the 'trigger'
      def perform!
        super

        dump = "echo '.dump' | #{sqlitedump_utility} #{path}"

        pipeline = Pipeline.new
        dump_ext = "sql".dup

        pipeline << dump
        if model.compressor
          model.compressor.compress_with do |command, ext|
            pipeline << command
            dump_ext << ext
          end
        end

        pipeline << "cat > '#{File.join(dump_path, dump_filename)}.#{dump_ext}'"

        pipeline.run

        if pipeline.success?
          log!(:finished)
        else
          raise Error,
            "#{database_name} Dump Failed!\n" + pipeline.error_messages
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
backupii-0.1.0.pre.alpha.2 lib/backup/database/sqlite.rb
backupii-0.1.0.pre.alpha.1 lib/backup/database/sqlite.rb