Created
December 16, 2013 22:30
-
-
Save jalberto/7995632 to your computer and use it in GitHub Desktop.
Simple Rails backup script using Backup gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/backup.rake | |
namespace :backup do | |
desc "Back up the database" | |
task :db do | |
sh "backup perform --trigger backupdb --config_file config/backup.rb --data-path db --log-path log --tmp-path tmp" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# config/backup.rb | |
## | |
# Backup Generated: backupdb | |
# Once configured, you can run the backup with the following command: | |
# | |
# $ backup perform -t backupdb [-c <path_to_configuration_file>] | |
# | |
database_yml = File.expand_path('../config/database.yml', __FILE__) | |
RAILS_ENV = ENV['RAILS_ENV'] || 'development' | |
require 'yaml' | |
config = YAML.load_file(database_yml) | |
Model.new(:backupdb, 'DB 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 | |
## | |
# PostgreSQL [Database] | |
# | |
database PostgreSQL do |db| | |
# To dump all databases, set `db.name = :all` (or leave blank) | |
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.socket = "/tmp/pg.sock" | |
# When dumping all databases, `skip_tables` and `only_tables` are ignored. | |
db.skip_tables = [] | |
db.only_tables = [] | |
db.additional_options = ["-xc", "-E=utf8"] | |
end | |
## | |
# Local (Copy) [Storage] | |
# | |
store_with Local do |local| | |
local.path = "~/backups/" | |
local.keep = 5 | |
end | |
## | |
# Bzip2 [Compressor] | |
# | |
compress_with Bzip2 | |
## | |
# Mail [Notifier] | |
# | |
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.mandrillapp.com" | |
mail.port = 587 | |
mail.domain = "foo.com" | |
mail.user_name = "[email protected]" | |
mail.password = "1234567890" | |
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