Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:40:12+00:00 2026-05-27T01:40:12+00:00

I’m using meskyanichi’s backup gem . By and large it does what I need

  • 0

I’m using meskyanichi’s backup gem. By and large it does what I need it to, but I need to have multiple backups (e.g., hourly, daily, weekly). The configurations are mostly the same but have a few differences, so I need to have multiple configuration files. I’m having trouble finding a sane way to manage the common bits of configurations (i.e., not repeat the common parts).

The configuration files use a lot of block structures, and from what I can tell, each backup needs to have a separate config file (e.g. config/backup/hourly.rb, config/backup/daily.rb, etc). A typical config file looks like this:

Backup::Model.new(:my_backup, 'My Backup') do

  database MySQL do |db|
    db.name               = "my_database"
    db.username           = "foo"
    db.password           = "bar"
    # etc
  end

  # similar for other config options

end

Then the backup is executed a la bundle exec backup perform -t my_backup -c path/to/config.rb.

My first swag at enabling a common config was to define methods that I could call from the blocks:

def my_db_config db
  db.name = "my_database"
  # etc
end

Backup::Model.new(:my_backup, 'My Backup') do
  database MySQL do |db|
    my_db_config db
  end
  #etc
end

But this fails with an undefined method 'my_db_config' for #<Backup::Database::MySQL:0x10155adf0>.

My intention was to get this to work and then split the common config functions into another file that I could require in each of my config files. I also tried creating a file with the config code and requireing it into the model definition block:

# common.rb
database MySQL do |db|
  db.name = "my_database"
  #etc
end

# config.rb
Backup::Model.new(:my_backup, 'My Backup') do
  require "common.rb" # with the right path, etc
end

This also doesn’t work, and from subsequent research I’ve discovered that that’s just not the way that require works. Something more in line with the way that C/C++’s #include works (i.e., blindly pasting the contents into whatever scope it is called from) might work.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:40:13+00:00Added an answer on May 27, 2026 at 1:40 am

    The gem seems to modify the execution scope of the config blocks. To work around this, you could wrap your functions in a class:

    class MyConfig
      def self.prepare_db(db)
        db.name = "my_database"
        # etc
        db
      end
    end
    
    Backup::Model.new(:my_backup, 'My Backup') do
      database MySQL do |db|
        db = MyConfig.prepare_db(db)
      end
      #etc
    end
    

    You could get a bit more fancy and abstract your default config merge:

    class BaseConfig
      @@default_sets = 
        :db => {
          :name => "my_database"
        },
        :s3 => {
          :access_key => "my_s3_key"
        }
      }
    
      def self.merge_defaults(initial_set, set_name)
        @@default_sets[set_name].each do |k, v|
          initial_set.send("#{k}=".to_sym, v)
        end
        initial_set
      end
    end
    
    Backup::Model.new(:my_backup, 'My Backup') do
      database MySQL do |db|
        db = BaseConfig.merge_defaults(db, :db)
      end
    
      store_with S3 do |s3|
        s3 = BaseConfig.merge_defaults(s3, :s3)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.