Sha256: 579b187042070e0b7fd1b94ef222645b6ef610b3db35f32f915c02043c40b5b2

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require_relative './postgres_helper'
namespace :pg do
  include PostgresHelper

  task :dump do
    backup_path = config[:backup_path]
    backups_enabled = config[:backups_enabled]
    external_backup = config[:external_backup]

    unless backups_enabled
      puts 'dump: Backups are disabled'
      exit(0)
    end

    notification = Notification::Api.new
    commandlist = dump_cmd(config)

    system "mkdir -p #{backup_path}" unless Dir.exist?(backup_path)

    result = system(commandlist)

    if ENV['BACKUP_PROVIDER'].present? && external_backup && result
      puts "Uploading #{@filename} to #{ENV['BACKUP_PROVIDER']}..."
      provider = Backup::Api.new
      begin
        provider.upload("#{@backup_path}/#{@filename}", @filename.to_s)
        puts "#{@filename} uploaded to #{ENV['BACKUP_PROVIDER']}"
      rescue StandardError => e
        puts "#{@filename} upload failed: #{e.message}"
      end
    end
    notification.send_backup_notification(result, title, content(result, { database: @database, backup_path: @backup_path, filename: @filename }),
                                          { date: @date, backup_path: @backup_path, database: @database })
    puts result ? "Backup created: #{@backup_path}/#{@filename} (#{size_str(File.size("#{@backup_path}/#{@filename}"))})" : 'Backup failed removing dump file'

    system "rm #{@backup_path}/#{@filename}" unless result
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-ops-0.2.5 lib/capistrano/ops/tasks/pg/dump.rake