Skip to content

Commit

Permalink
Fixes #36480 - add restore_dir option to backup_local
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Evgeni Golov <[email protected]>
(cherry picked from commit c8bdc1c)
  • Loading branch information
martin-schlossarek authored and evgeni committed Aug 16, 2023
1 parent fd5b2d5 commit 69508d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion definitions/procedures/backup/offline/candlepin_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions definitions/procedures/backup/offline/foreman_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion definitions/procedures/backup/offline/pulpcore_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman_maintain/concerns/base_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 69508d4

Please sign in to comment.