Skip to content

Instantly share code, notes, and snippets.

@FUT
Last active March 28, 2016 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FUT/3f2178987b429a156585 to your computer and use it in GitHub Desktop.
Save FUT/3f2178987b429a156585 to your computer and use it in GitHub Desktop.
Backup PSQL and S3
Logger.configure do
syslog.ident = File.dirname(__FILE__) + "/../../log/radium_backup"
end
Model.new(:my_full_backup, 'Description for my_full_backup') do
database PostgreSQL do |db|
db.name = "my_database"
db.username = "user"
db.password = "pwd"
db.host = "localhost"
db.port = 5432
db.additional_options = ["-xc", "-E=utf8"]
end
time = Time.now
if time.day == 1 # first day of the month
storage_id = :monthly
keep = 6
elsif time.sunday?
storage_id = :weekly
keep = 3
else
storage_id = :daily
keep = 12
end
store_with S3, storage_id do |s3|
# AWS Credentials
s3.access_key_id = "key"
s3.secret_access_key = "secret"
# Or, to use a IAM Profile:
# s3.use_iam_profile = true
s3.region = "us-east-1"
s3.bucket = "my-backups"
s3.path = "backups/#{ storage_id }"
s3.keep = keep
end
notify_by Mail do |mail|
mail.on_success = false
mail.on_warning = true
mail.on_failure = true
mail.from = "db-backups@test.com"
mail.to = "me@test.com"
mail.reply_to = "noreply@test.com"
mail.address = "smtp.sendgrid.net"
mail.port = 587
mail.domain = "test.com"
mail.user_name = "user"
mail.password = "pwd"
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