ruby 用于备份Postgresql到Dropbox帐户的备份文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 用于备份Postgresql到Dropbox帐户的备份文件相关的知识,希望对你有一定的参考价值。


# encoding: utf-8

##
# Backup Generated: my_backup
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t my_backup [-c <path_to_configuration_file>]
#

database_yml = File.expand_path('/opt/deployed/application/current/config/database.yml',  __FILE__)
RAILS_ENV    = ENV['RAILS_ENV'] || 'production'

require 'yaml'
config = YAML.load_file(database_yml)

Backup::Model.new(:my_backup, 'Backup for the my\'s production instance') do
  ##
  # Split [Splitter]
  #
  # Split the backup file in to chunks of 250 megabytes
  # if the backup file size exceeds 250 megabytes
  #
  split_into_chunks_of 250

  ##
  # PostgreSQL [Database]
  #
  database PostgreSQL do |db|
    db.name               = config[RAILS_ENV]["database"]
    db.username           = config[RAILS_ENV]["username"]
    db.password           = config[RAILS_ENV]["password"]
    db.host               = config[RAILS_ENV]["host"]
    db.port               = config[RAILS_ENV]["port"]
    db.skip_tables        = []
    db.additional_options = ["-xc", "-E=utf8"]
    # Optional: Use to set the location of this utility
    #   if it cannot be found by name in your $PATH
    # db.pg_dump_utility = "/opt/local/bin/pg_dump"
  end

  ##
  # Dropbox File Hosting Service [Storage]
  #
  # Access Type:
  #
  #  - :app_folder (Default)
  #  - :dropbox
  #
  # Note:
  #
  #  Initial backup must be performed manually to authorize
  #  this machine with your Dropbox account.
  #
  store_with Dropbox do |db|
    db.api_key     = "api_key"
    db.api_secret  = "api_secret"
    db.access_type = :app_folder
    db.path        = "backups"
    db.keep        = 25
  end

  ##
  # Mail [Notifier]
  #
  # The default delivery method for Mail Notifiers is 'SMTP'.
  # See the Wiki for other delivery options.
  # https://github.com/meskyanichi/backup/wiki/Notifiers
  #
  notify_by Mail do |mail|
    mail.on_success           = true
    mail.on_warning           = true
    mail.on_failure           = true

    mail.from                 = "correo@ejemplo.com"
    mail.to                   = "correo@ejemplo.com"
    mail.address              = "smtp.gmail.com"
    mail.port                 = 587
    mail.domain               = "dominio"
    mail.user_name            = "correo@ejemplo.com"
    mail.password             = "pa$$word"
    mail.authentication       = "plain"
    mail.enable_starttls_auto = true
  end

  compress_with Gzip do |compression|
    compression.level = 6
  end

end

以上是关于ruby 用于备份Postgresql到Dropbox帐户的备份文件的主要内容,如果未能解决你的问题,请参考以下文章

ruby 用于从给定的aws帐户备份所有simpledb表的脚本

Postgresql - 备份数据库并恢复不同的所有者?

Barman安装及备份PostgreSQL

postgresql如何备份数据库

PostgreSQL备份与恢复(第三章)

PostgreSQL 数据库导入导出