Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Postgres] Add ability to backup all databases #375

Closed
wants to merge 2 commits into from

3 participants

@guilhem

This patches work like mysql.

No name will backup all databases.

guilhem added some commits
@guilhem guilhem Add ability to backup all Postgres.
You can use it in the same way than mysql without giving a name or with name "all".
You can set the pg_dump_all utility with "db.pg_dump_all_utility"
3398ca4
@guilhem guilhem clean-up code.
I follow code from mysql part.
fa36344
@maxmeyer

+1 works for me too.

@tomash

will test it this weekend and merge if there are no fuckups

@ghost Unknown closed this pull request from a commit
Brian D. Burns add option to dump all PostgreSQL databases (closes #375) fc26b05
@ghost ghost closed this in fc26b05
@guilhem guilhem deleted the branch
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 5, 2012
  1. @guilhem

    Add ability to backup all Postgres.

    guilhem authored
    You can use it in the same way than mysql without giving a name or with name "all".
    You can set the pg_dump_all utility with "db.pg_dump_all_utility"
  2. @guilhem

    clean-up code.

    guilhem authored
    I follow code from mysql part.
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 2 deletions.
  1. +34 −2 lib/backup/database/postgresql.rb
View
36 lib/backup/database/postgresql.rb
@@ -32,6 +32,10 @@ class PostgreSQL < Base
# Path to pg_dump utility (optional)
attr_accessor :pg_dump_utility
+ ##
+ # Path to pg_dumpall utility (optional)
+ attr_accessor :pg_dumpall_utility
+
attr_deprecate :utility_path, :version => '3.0.21',
:replacement => :pg_dump_utility
@@ -48,7 +52,9 @@ def initialize(model, &block)
instance_eval(&block) if block_given?
+ @name ||= :all
@pg_dump_utility ||= utility(:pg_dump)
+ @pg_dumpall_utility ||= utility(:pg_dumpall)
end
##
@@ -60,14 +66,14 @@ def perform!
pipeline = Pipeline.new
dump_ext = 'sql'
- pipeline << pgdump
+ pipeline << command
if @model.compressor
@model.compressor.compress_with do |command, ext|
pipeline << command
dump_ext << ext
end
end
- pipeline << "cat > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"
+ pipeline << "cat > '#{ File.join(@dump_path, dump_filename) }.#{ dump_ext }'"
pipeline.run
if pipeline.success?
@@ -80,6 +86,12 @@ def perform!
end
##
+ # return the command to use
+ def command
+ dump_all? ? pgdumpall : pgdump
+ end
+
+ ##
# Builds the full pgdump string based on all attributes
def pgdump
"#{password_options}" +
@@ -87,6 +99,18 @@ def pgdump
"#{ user_options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
end
+ def pgdumpall
+ "#{password_options}" +
+ "#{ pg_dumpall_utility } #{ username_options } #{ connectivity_options } " +
+ "#{ user_options }"
+ end
+
+ ##
+ # Returns the filename to use for dumping the database(s)
+ def dump_filename
+ dump_all? ? 'all-databases' : name
+ end
+
##
# Builds the password syntax PostgreSQL uses to authenticate the user
# to perform database dumping
@@ -138,6 +162,14 @@ def tables_to_skip
end.join(' ')
end
+ ##
+ # Return true if we're dumping all databases.
+ # `name` will be set to :all if it is not set,
+ # so this will be true by default
+ def dump_all?
+ name == :all
+ end
+
end
end
end
Something went wrong with that request. Please try again.