Skip to content

Instantly share code, notes, and snippets.

@ouyangzhiping
Last active June 9, 2018 10:33
Show Gist options
  • Save ouyangzhiping/6189731 to your computer and use it in GitHub Desktop.
Save ouyangzhiping/6189731 to your computer and use it in GitHub Desktop.
Backing Up PostgreSQL With Backup and Whatever Gems with Drobpbox api

create backup project

bundle exec backup generate:model --trigger my_backup --archives --storages='dropbox' --compressors='gzip' --notifiers='mail' --databases="postgresql"

dropbox api

https://www.dropbox.com/developers/apps

gemfile

source 'https://rubygems.org'
gem 'backup'
gem 'whenever'
gem 'capistrano'
group :development do
  gem 'capistrano-ext'
end

whenever

mkdir config
bundle exec wheneverize .

result:

[add] writing `./config/schedule.rb'
[done] wheneverized!

edit `./config/schedule.rb'

every 1.day, :at => '2:30 am' do
  command "backup perform --trigger my_backup"
end
# 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>]
#
Backup::Model.new(:my_backup, 'Description for my_backup') 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
##
# Archive [Archive]
#
# Adding a file or directory (including sub-directories):
# archive.add "/path/to/a/file.rb"
# archive.add "/path/to/a/directory/"
#
# Excluding a file or directory (including sub-directories):
# archive.exclude "/path/to/an/excluded_file.rb"
# archive.exclude "/path/to/an/excluded_directory
#
# By default, relative paths will be relative to the directory
# where `backup perform` is executed, and they will be expanded
# to the root of the filesystem when added to the archive.
#
# If a `root` path is set, relative paths will be relative to the
# given `root` path and will not be expanded when added to the archive.
#
# archive.root '/path/to/archive/root'
#
# For more details, please see:
# https://github.com/meskyanichi/backup/wiki/Archives
#
archive :my_archive do |archive|
# Run the `tar` command using `sudo`
# archive.use_sudo
archive.add "/path/to/a/file.rb"
archive.add "/path/to/a/folder/"
archive.exclude "/path/to/a/excluded_file.rb"
archive.exclude "/path/to/a/excluded_folder"
end
##
# PostgreSQL [Database]
#
database PostgreSQL do |db|
db.name = "my_database_name"
db.username = "my_username"
db.password = "my_password"
db.host = "localhost"
db.port = 5432
db.socket = "/tmp/pg.sock"
db.skip_tables = ["skip", "these", "tables"]
db.only_tables = ["only", "these", "tables"]
db.additional_options = ["-xc", "-E=utf8"]
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 = "my_api_key"
db.api_secret = "my_api_secret"
db.access_type = :app_folder
db.path = "/path/to/my/backups"
db.keep = 25
end
##
# Gzip [Compressor]
#
compress_with Gzip
##
# 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 = "[email protected]"
mail.to = "[email protected]"
mail.address = "smtp.gmail.com"
mail.port = 587
mail.domain = "your.host.name"
mail.user_name = "[email protected]"
mail.password = "my_password"
mail.authentication = "plain"
mail.encryption = :starttls
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment