mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 10:15:48 +08:00
FIX: Restore process for dump taken with pg_dump
10.3+.
* Since we can no longer restore into a different schema, we will move tables in the public schema into the backup schema first before restoring the dump file which goes into the public schema. The downside to this approach is that we will increase the downtime experienced during the restore process. Downtime would equal the duration of restoring the dump file.
This commit is contained in:
parent
ab1ca72865
commit
3bccd8c8f3
|
@ -39,9 +39,27 @@ module BackupRestore
|
|||
validate_metadata
|
||||
|
||||
extract_dump
|
||||
restore_dump
|
||||
dumped_by_version = Gem::Version.new(get_dumped_by_version)
|
||||
|
||||
### READ-ONLY / START ###
|
||||
if dumped_by_version >= Gem::Version.new("10.3") ||
|
||||
dumped_by_version >= Gem::Version.new("9.5.12")
|
||||
|
||||
enable_readonly_mode
|
||||
|
||||
pause_sidekiq
|
||||
wait_for_sidekiq
|
||||
|
||||
BackupRestore.move_tables_between_schemas("public", "backup")
|
||||
restore_dump
|
||||
migrate_database
|
||||
reconnect_database
|
||||
|
||||
reload_site_settings
|
||||
clear_emoji_cache
|
||||
|
||||
disable_readonly_mode
|
||||
else
|
||||
restore_dump
|
||||
enable_readonly_mode
|
||||
|
||||
pause_sidekiq
|
||||
|
@ -55,7 +73,7 @@ module BackupRestore
|
|||
clear_emoji_cache
|
||||
|
||||
disable_readonly_mode
|
||||
### READ-ONLY / END ###
|
||||
end
|
||||
|
||||
extract_uploads
|
||||
rescue SystemExit
|
||||
|
@ -238,6 +256,16 @@ module BackupRestore
|
|||
end
|
||||
end
|
||||
|
||||
def get_dumped_by_version
|
||||
output = Discourse::Utils.execute_command(
|
||||
File.extname(@dump_filename) == '.gz' ? 'zgrep' : 'grep',
|
||||
'-m1', @dump_filename, '-e', "pg_dump",
|
||||
failure_message: "Failed to check version of pg_dump used to generate the dump file"
|
||||
)
|
||||
|
||||
output.match(/version (\d+(\.\d+)?)/)[1]
|
||||
end
|
||||
|
||||
def restore_dump_command
|
||||
if File.extname(@dump_filename) == '.gz'
|
||||
"gzip -d < #{@dump_filename} | #{sed_command} | #{psql_command} 2>&1"
|
||||
|
|
Loading…
Reference in New Issue
Block a user