I'm liking the profiles feature in 2.x. For those of us using Backup and Migrate on multiple sites a killer feature would be the ability to import and export these profiles so that one doesn't have to manually configure every site's backup routine.

Comments

ronan’s picture

Good idea, I'll make it a todo. Version 1.x stored all settings in the variables table, so you could configure it in settings.php but that's no longer possible as the module's gotten quite a bit more complicated.

I'd like to see some sort of file based configuration rather than importing and exporting settings since then you'd be able to version control your settings, and they'd be immune to database changes (helpful for this particular module).

For exporting and importing settings, you could use the module itself to export only the tables starting with 'backup_migrate_'.

R

rickvug’s picture

Title: import/export backup profiles » Add option to store backup profiles in code

I agree that adding the ability to store configuration in code is the way to go (issue re-titled accordingly). Views is an excellent example of how configuration can be set in code and then overridden as needed with a database version. It also has export capabilities. Some of those features are "nice to haves" but its good to have something to shoot for. If you need a someone to test a dev release with this functionality just let me know. :)

ronan’s picture

Views is what I had in mind too. I like how it works and would probably model my solution on that.

If you're not afraid of a little PHP, you can get that effect right now by creating a custom module and implementing HOOK_backup_migrate_profiles. It takes no arguments and should return an array of profiles. With no export feature you'll have to build the profiles by hand, but here's an example to get you started:

function mymodule_backup_migrate_profiles() {
  return array('mydefaults' => array(
    'name' => 'My Defaults',
    'source' => 'db_url:default',
    'exclude_tables' => array('table1, 'table2'),
    'nodata_tables' => array('table1, 'table2'),
    'filters' => array('compression' => 'gzip'),
    'filename' => '[sitename]',
    'append_timestamp' => TRUE,
    'timestamp_format' => 'Y-m-d\TH-i-s'
  ));
}

Code not tested, so it probably has some stupid parse error in it.

There are similar hooks for schedules and destinations.

I hope this helps tide you over until I'm able to get to import/export.

Ronan

ronan’s picture

The latest dev has 'exportables' capability built in. To export a profile, schedule or destination, install the chaos tools module (http://drupal.org/project/ctools) and export links will appear in the listings for those items. You only need ctools to export and can turn it off when you are happy with what you've exported.

To expose the exported items to backup and migrate you can then either use a custom module and the method described in http://drupal.org/node/373786#comment-1260099 above or you can add them to your $conf variable in settings.php as shown below:

// Inside settings.php

$conf['backup_migrate_profiles_defaults'][] = array(
  'profile_id' => 'default_49b2bfe161592',
  'name' => 'Default Profile',
  'exclude_tables' => array(),
  'source_id' => 'db_url:default',
  'nodata_tables' => array(
    'cache' => 'cache',
    'cache_filter' => 'cache_filter',
    'cache_menu' => 'cache_menu',
    'cache_page' => 'cache_page',
    'cache_views' => 'cache_views',
    'devel_queries' => 'devel_queries',
    'devel_times' => 'devel_times',
    'sessions' => 'sessions',
    'watchdog' => 'watchdog',
  ),
  'filename' => 'chmodtest',
  'append_timestamp' => '1',
  'timestamp_format' => 'Y-m-d\\TH-i-s',
  'filters' => array(
    'compression' => 'none',
    'notify_success_email' => '',
    'notify_failure_email' => '',
  ),
);
$conf['backup_migrate_profiles_defaults'][] = array(
 // Any other exported destination.
);

$conf['backup_migrate_destinations_defaults'][] = array(
  'type' => 'file',
  'destination_id' => 'default_49b2bfe161593',
  'name' => 'My Test Destination',
  'location' => 'sites/default/files/backup_migrate/manual',
  'settings' => array(
    'chmod' => '',
    'chown' => '',
    'chgrp' => '',
  ),
);

$conf['backup_migrate_schedules_defaults'][] = array(
  'schedule_id' => 'default_49b2c1f3e2377',
  'name' => 'My Test Schedule',
  'destination_id' => 'default_49b2bfe161593',
  'profile_id' => '1',
  'keep' => '3',
  'period' => '1',
  'last_run' => '0',
  'enabled' => '1',
  'cron' => '0',
);

If you want the items to depend on each other, be sure to export them one at a time, or change the ids by hand.

Let me know if this works and if you have any issues with it. I may change the formats slightly and if I do I'll update this thread so you know how to change your defaults.

Thanks
Ronan

ronan’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rickvug’s picture

Issue tags: +CTools exportables

I forgot to say thank you for this. Thanks! Also, using cTools for this 9 months ago seems to have been solid foresight with Features module integration.

Tor Arne Thune’s picture

Status: Closed (fixed) » Needs work

Inside settings.php this works great, but I also tried it in a custom module, and I got these errors when I ran drush bam-profiles:

WD php: Warning: Attempt to assign property of non-object in backup_migrate_backup_migrate_profiles_alter() (line 33 of /home/user/Public/Sites/drupal/sites/all/modules/backup_migrate/includes/profiles.inc).
PHP Fatal error:  Call to a member function get_id() on a non-object in /home/user/Public/Sites/drupal/sites/all/modules/backup_migrate/includes/backup_migrate.drush.inc on line 173
Drush command terminated abnormally due to an unrecoverable error.
Error: Call to a member function get_id() on a non-object in /home/user/Public/Sites/drupal/sites/all/modules/backup_migrate/includes/backup_migrate.drush.inc, line 173

Here is the mymodule_backup_migrate_profiles in mymodule.install:

  return array('snapshot' => array(
    'name' => 'Snapshot',
    'filename' => '[site:name]',
    'append_timestamp' => '1',
    'timestamp_format' => 'Y-m-d\\TH-i-s',
    'filters' => array(
      'compression' => 'gzip',
      'notify_success_enable' => 0,
      'notify_success_email' => '',
      'notify_failure_enable' => 0,
      'notify_failure_email' => '',
      'utils_site_offline' => 0,
      'utils_site_offline_message' => '',
      'destinations' => array(
        'db' => array(
          'exclude_tables' => array (),
          'nodata_tables' => array(
            'cache' => 'cache',
            'cache_admin_menu' => 'cache_admin_menu',
            'cache_block' => 'cache_block',
            'cache_bootstrap' => 'cache_bootstrap',
            'cache_field' => 'cache_field',
            'cache_filter' => 'cache_filter',
            'cache_form' => 'cache_form',
            'cache_image' => 'cache_image',
            'cache_media_xml' => 'cache_media_xml',
            'cache_menu' => 'cache_menu',
            'cache_page' => 'cache_page',
            'cache_path' => 'cache_path',
            'cache_update' => 'cache_update',
            'ctools_css_cache' => 'ctools_css_cache',
            'ctools_object_cache' => 'ctools_object_cache',
            'flood' => 'flood',
            'history' => 'history',
            'search_dataset' => 'search_dataset',
            'search_index' => 'search_index',
            'search_total' => 'search_total',
            'sessions' => 'sessions',
            'watchdog' => 'watchdog',
          ),
          'utils_lock_tables' => 0,
        ),
      ),
      'utils_disable_query_log' => TRUE,
    ),
  ));

I also tried with the code from #3 and got the same errors:

  return array('snapshot' => array(
    'name' => 'Snapshot',
    'source' => 'db_url:default',
    'exclude_tables' => array('table1', 'table2'),
    'nodata_tables' => array('table1', 'table2'),
    'filters' => array('compression' => 'gzip'),
    'filename' => '[sitename]',
    'append_timestamp' => TRUE,
    'timestamp_format' => 'Y-m-d\TH-i-s'
  ));
Tor Arne Thune’s picture

Version: 6.x-2.x-dev » 7.x-2.2
jdleonard’s picture

sub

TravisCarden’s picture

Status: Needs work » Closed (duplicate)

Since the module no longer uses simple Drupal variables, I'm closing this in favor of #1001654: Make backup profiles and schedules Features exportable.