From c8bdc1cc22b40f4bb12a9106d864907bad4aa3a3 Mon Sep 17 00:00:00 2001 From: Martin Schlossarek <33715215+martin-schlossarek@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:19:15 +0200 Subject: [PATCH] Fixes #36480 - add restore_dir option to backup_local Without a restore_dir option, snapshot backups cannot be restored with "foreman-maintain restore". Only adjust restore_dir on EL-based systems We do not support snapshots on Debian-based systems right now, and the differences in the DB setup would break normal backups on Debian otherwise. --------- Co-authored-by: Martin Schlossarek Co-authored-by: Evgeni Golov --- definitions/procedures/backup/offline/candlepin_db.rb | 3 ++- definitions/procedures/backup/offline/foreman_db.rb | 2 ++ definitions/procedures/backup/offline/pulpcore_db.rb | 3 ++- lib/foreman_maintain/concerns/base_database.rb | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/definitions/procedures/backup/offline/candlepin_db.rb b/definitions/procedures/backup/offline/candlepin_db.rb index f00a6411e..5d2c94329 100644 --- a/definitions/procedures/backup/offline/candlepin_db.rb +++ b/definitions/procedures/backup/offline/candlepin_db.rb @@ -36,7 +36,8 @@ def local_backup pg_backup_file, :listed_incremental => File.join(@backup_dir, '.postgres.snar'), :volume_size => @tar_volume_size, - :data_dir => pg_data_dir + :data_dir => pg_data_dir, + :restore_dir => feature(:candlepin_database).data_dir ) end end diff --git a/definitions/procedures/backup/offline/foreman_db.rb b/definitions/procedures/backup/offline/foreman_db.rb index cd73c6465..2566077a5 100644 --- a/definitions/procedures/backup/offline/foreman_db.rb +++ b/definitions/procedures/backup/offline/foreman_db.rb @@ -39,11 +39,13 @@ def local_backup end def do_backup(pg_dir, cmd) + restore_dir = el? ? feature(:foreman_database).data_dir : pg_dir feature(:foreman_database).backup_local( pg_backup_file, :listed_incremental => File.join(@backup_dir, '.postgres.snar'), :volume_size => @tar_volume_size, :data_dir => pg_dir, + :restore_dir => restore_dir, :command => cmd ) end diff --git a/definitions/procedures/backup/offline/pulpcore_db.rb b/definitions/procedures/backup/offline/pulpcore_db.rb index 5aba2efc1..94a79a784 100644 --- a/definitions/procedures/backup/offline/pulpcore_db.rb +++ b/definitions/procedures/backup/offline/pulpcore_db.rb @@ -36,7 +36,8 @@ def local_backup pg_backup_file, :listed_incremental => File.join(@backup_dir, '.postgres.snar'), :volume_size => @tar_volume_size, - :data_dir => pg_data_dir + :data_dir => pg_data_dir, + :restore_dir => feature(:pulpcore_database).data_dir ) end end diff --git a/lib/foreman_maintain/concerns/base_database.rb b/lib/foreman_maintain/concerns/base_database.rb index 1fea0d59f..33c4446f3 100644 --- a/lib/foreman_maintain/concerns/base_database.rb +++ b/lib/foreman_maintain/concerns/base_database.rb @@ -101,13 +101,14 @@ def restore_dump(file, localdb, config = configuration) def backup_local(backup_file, extra_tar_options = {}) dir = extra_tar_options.fetch(:data_dir, data_dir) + restore_dir = extra_tar_options.fetch(:restore_dir, data_dir) command = extra_tar_options.fetch(:command, 'create') FileUtils.cd(dir) do tar_options = { :archive => backup_file, :command => command, - :transform => "s,^,#{dir[1..]},S", + :transform => "s,^,#{restore_dir[1..]},S", :files => '*', }.merge(extra_tar_options) feature(:tar).run(tar_options)