Class: UBSafe::Commands::PostgresBackup
- Defined in:
- lib/ubsafe/ubsafe_commands/ubsafe_command_backup_postgres.rb
Instance Method Summary collapse
-
#after_clean_source ⇒ Symbol
Hook to allow customization after cleaning source.
-
#before_source_backup ⇒ Symbol
Hook to allow customization before creating source backup.
Methods inherited from Backup
#after_copy_backup, #after_rotate_destination_files, #after_source_backup, #all_backup_names, #backup, #before_clean_source, #before_copy_backup, #before_rotate_destination_files, #clean_source, #copy_backup, #create_and_copy_backup, #create_source_backup, #email_notify, #get_backup_file_name, #get_backup_file_name_with_generation, #get_remote_modified_timestamp, #initialize, instance, #remote_file_exists?, #rotate_destination_files, #rotate_destination_files_unconditionally, #scp_cmd, #ssh_cmd
Constructor Details
This class inherits a constructor from UBSafe::Commands::Backup
Instance Method Details
#after_clean_source ⇒ Symbol
Hook to allow customization after cleaning source
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ubsafe/ubsafe_commands/ubsafe_command_backup_postgres.rb', line 38 def after_clean_source tmp_dir = File.(@backup_options[:temporary_directory]) postgres_tmp_dir = File.join(tmp_dir,'postgres') cmd_output = `rm -rf #{postgres_tmp_dir}` cmd_status = $? cmd_status == 0 ? :success : :failure if cmd_status == :failure @log.error("Backup #{@backup_name} after_clean_source failed. Output #{cmd_output}") end return cmd_status end |
#before_source_backup ⇒ Symbol
Hook to allow customization before creating source backup
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ubsafe/ubsafe_commands/ubsafe_command_backup_postgres.rb', line 14 def before_source_backup tmp_dir = File.(@backup_options[:temporary_directory]) postgres_tmp_dir = File.join(tmp_dir,'postgres') FileUtils.mkdir_p(postgres_tmp_dir) cmd = "#{@backup_options[:postgres_bin_dir]}/pg_dump -U#{@backup_options[:postgres_username]} -h#{@backup_options[:postgres_host]} -p#{@backup_options[:postgres_port]} #{@backup_options[:postgres_database]} >#{postgres_tmp_dir}/#{@backup_options[:postgres_database]}.sql" @log.info("Backup #{@backup_name} \"pg_dump -U#{@backup_options[:postgres_username]} -h#{@backup_options[:postgres_host]} -p#{@backup_options[:postgres_port]} #{@backup_options[:postgres_database]} >#{postgres_tmp_dir}/#{@backup_options[:postgres_database]}.sql\"") cmd_output = `#{cmd}` cmd_status = $? cmd_status = cmd_status == 0 ? :success : :failure if cmd_status == :failure # cleanup cmd_output = `rm -rf #{postgres_tmp_dir}` @log.error("Backup #{@backup_name} before_source_backup failed during pg_dump. Output #{cmd_output}") end # Point source to directory with dump file in it so rest of the world works @backup_options[:source_tree] = postgres_tmp_dir return cmd_status end |