example_backup.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # This file contains an example template for using the Backup gem for backing up your Huginn installation to S3.
  2. # In your crontab do something like:
  3. # 0 0,12 * * * /bin/bash -l -c "RAILS_ENV=production backup perform -t huginn_backup --config_file /home/you/huginn_backup.rb" 2>&1 >> /home/you/huginn_backup_log.txt
  4. # In backups.password on your server:
  5. # some password
  6. # In huginn_backup.rb on your server put an edited version of the following file. REMEMBER TO EDIT THE FILE!
  7. # You'll also need to install the backup gem on your server, as well as the net-ssh, excon, net-scp, and fog gems.
  8. database_yml = '/home/you/app/current/config/database.yml'
  9. rails_env = ENV['RAILS_ENV'] || 'production'
  10. require 'yaml'
  11. config = YAML.load_file(database_yml)
  12. Backup::Model.new(:huginn_backup, 'The Huginn backup configuration') do
  13. split_into_chunks_of 4000
  14. database MySQL do |database|
  15. database.name = config[rails_env]["database"]
  16. database.username = config[rails_env]["username"]
  17. database.password = config[rails_env]["password"]
  18. database.host = config[rails_env]["host"]
  19. database.port = config[rails_env]["port"]
  20. database.socket = config[rails_env]["socket"]
  21. database.additional_options = ['--single-transaction', '--quick', '--hex-blob', '--add-drop-table']
  22. end
  23. encrypt_with OpenSSL do |encryption|
  24. encryption.password_file = "/home/you/backups.password"
  25. encryption.base64 = true
  26. encryption.salt = true
  27. end
  28. compress_with Gzip do |compression|
  29. compression.level = 8
  30. end
  31. store_with S3 do |s3|
  32. s3.access_key_id = 'YOUR_AWS_ACCESS_KEY'
  33. s3.secret_access_key = 'YOUR_AWS_SECRET'
  34. s3.region = 'us-east-1'
  35. s3.bucket = 'my-huginn-backups'
  36. s3.keep = 20
  37. end
  38. notify_by Mail do |mail|
  39. mail.on_success = false
  40. mail.on_warning = true
  41. mail.on_failure = true
  42. mail.from = 'you@example.com'
  43. mail.to = 'you@example.com'
  44. mail.address = 'smtp.gmail.com'
  45. mail.domain = "example.com"
  46. mail.user_name = 'you@example.com'
  47. mail.password = 'password'
  48. mail.port = 587
  49. mail.authentication = "plain"
  50. mail.enable_starttls_auto = true
  51. end
  52. end