From 271febd31a64179c43e206012ddf546dfc375ee2 Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Mon, 23 Oct 2017 18:09:13 -0400 Subject: [PATCH] Use pg_basebackup rather than pg_dump for backing up the database This will allow us to backup all databases in the cluster as well as config files. https://bugzilla.redhat.com/show_bug.cgi?id=1495192 --- lib/gems/pending/util/postgres_admin.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/gems/pending/util/postgres_admin.rb b/lib/gems/pending/util/postgres_admin.rb index b3020e4ca..b51ac590b 100644 --- a/lib/gems/pending/util/postgres_admin.rb +++ b/lib/gems/pending/util/postgres_admin.rb @@ -130,17 +130,16 @@ def self.unload_pglogical_extension(opts) end def self.backup_pg_compress(opts) - # 3) - # Use pg_dump's custom dump format. If PostgreSQL was built on a system with - # the zlib compression library installed, the custom dump format will compress - # data as it writes it to the output file. This will produce dump file sizes - # similar to using gzip, but it has the added advantage that tables can be restored - # selectively. The following command dumps a database using the custom dump format: - opts = opts.dup - dbname = opts.delete(:dbname) - runcmd("pg_dump", opts, :format => "c", :file => opts[:local_file], nil => dbname) - opts[:local_file] + + # discard dbname as pg_basebackup does not connect to a specific database + opts.delete(:dbname) + + path = Pathname.new(opts.delete(:local_file)) + + runcmd("pg_basebackup", opts, :z => nil, :format => "t", :xlog_method => "fetch", :pgdata => path.dirname) + FileUtils.mv(path.dirname.join("base.tar.gz"), path) + path.to_s end def self.recreate_db(opts)