Integrate Backup with Rails, Whenever, Mongoid 3
Last active
December 14, 2015 21:18
-
-
Save linjunpop/5149756 to your computer and use it in GitHub Desktop.
Integrate Backup with Rails
This file contains hidden or 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 | |
| database_yml = File.expand_path('mongoid.yml', File.dirname(__FILE__)) | |
| RAILS_ENV = ENV['RAILS_ENV'] || 'development' | |
| require 'yaml' | |
| config = YAML.load_file(database_yml) | |
| Backup::Model.new(:mongodb, 'Backup mongodb') do | |
| ## | |
| # notifier | |
| # | |
| notify_by Mail do |mail| | |
| mail.on_success = true | |
| mail.on_warning = true | |
| mail.on_failure = true | |
| mail.from = 'from@example.com' | |
| mail.to = 'to@example.com' | |
| mail.address = 'smtp.gmail.com' | |
| mail.port = 587 | |
| mail.domain = 'example.com' | |
| mail.user_name = 'from@example.com' | |
| mail.password = 'pwdpwd' | |
| mail.authentication = 'plain' | |
| mail.enable_starttls_auto = true | |
| end | |
| ## | |
| # 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 | |
| ## | |
| # MongoDB [Database] | |
| # | |
| database MongoDB do |db| | |
| db.name = config[RAILS_ENV]['sessions']['default']["database"] | |
| db.username = config[RAILS_ENV]['sessions']['default']["username"] | |
| db.password = config[RAILS_ENV]['sessions']['default']["password"] | |
| db.host = config[RAILS_ENV]['sessions']['default']["hosts"][0] | |
| db.ipv6 = false | |
| db.additional_options = [] | |
| db.lock = false | |
| # Optional: Use to set the location of these utilities | |
| # if they cannot be found by their name in your $PATH | |
| # db.mongodump_utility = "/opt/local/bin/mongodump" | |
| # db.mongo_utility = "/opt/local/bin/mongo" | |
| end | |
| ## | |
| # Local (Copy) [Storage] | |
| # | |
| store_with Local do |local| | |
| local.path = "public/system/backups/" | |
| local.keep = 5 | |
| end | |
| end |
This file contains hidden or 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
| # config/schedule.rb | |
| job_type :backup, 'cd :path && RAILS_ENV=:environment bundle exec backup perform -t :task :configs' | |
| every 1.day, at: '02:01' do | |
| backup "mongodb", configs: "-c config/backup.rb --data-path public/system/backups/db --log-path public/system/backups/log --tmp-path public/system/backups/tmp" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment