The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mozilla::Backup - Backup utility for Mozilla profiles

SYNOPSIS

  $moz = Mozilla::Backup->new();
  $file = $moz->backup_profile("firefox", "default");

DESCRIPTION

This package provides a simple interface to back up and restore the profiles of Mozilla-related applications such as Firefox or Thunderbird.

Method calls may use named or positional parameters (named calls are recommended). Methods are outlined below:

new
  $moz = Mozilla::Backup->new( %options );

Creates a new Mozilla::Backup object. The options are as follows:

log

A Log::Dispatch object for receiving log messages.

This value is passed to plugins if they accept it.

plugin

A plugin to use for archiving. Plugins included are:

Mozilla::Backup::Plugin::Zip

Saves the profile in a zip archive. This is the default plugin.

Mozilla::Backup::Plugin::FileCopy

Copies the files in the profile into another directory.

Mozilla::Backup::Plugin::Tar

Saves the profile in a tar or tar.gz archive.

You may pass options to the plugin in the following manner:

  $moz = Mozilla::Backup->new(
    plugin => [ 'Mozilla::Backup::Plugin::Tar', compress => 1 ],
  );
exclude

An array reference of regular expressions for files to exclude from the backup. For example,

  $moz = Mozilla::Backup->new(
    exclude => [ '^history', '^Cache' ],
  );

Regular expressions can be strings or compiled Regexps.

By default the Cache, <Cache.Trash> folders, XUL cache, mail folders cache and lock files are excluded.

profile_types
  @types = $moz->profile_types;

Returns a list of all profile types that are supported by this version of the module.

Supported profile types:

  beonex
  camino
  firefox
  galeon
  kmeleon
  mozilla
  phoenix
  netscape
  sunbird
  thunderbird

Some of these profile types are for platform-specific or obsolete applications, so you may never run into them.

found_profile_types
  @types = $moz->found_profile_types();

Returns a list of applications for which profiles were found. (This does not mean that the applications are installed on the machine, only that profiles were found where they were expected.)

type
  $ini = $moz->type( type => $type );

  $ini = $moz->type( $type );

  if ($moz->type( $type )->profile_exists( $name )) { ... }

Returns the Mozilla::ProfilesIni object for the corresponding $type, or an error if it is invalid.

type_exists
  if ($moz->type_exists( type => $type)) { ... }

  if ($moz->type_exists($type)) { ... }

Returns true if a profile type exists on the machine.

backup_profile
  $file = $moz->backup_profile(
    type         => $type,
    name         => $name,
    destination  => $dest,
    archive_name => $arch,
    relative     => $rel,
  );

  $file = $moz->backup_profile($type,$name,$dest,$arch,$rel);

Backs up the profile as a zip archive to the path specified in $dest. (If none is given, the current directory is assumed.)

$arch is an optional name for the archive file. If none is given, it assumes type-name-date-time.ext (for example, mozilla-default-20050426-120000.zip if the Zip plugin is used.)

$rel is an optional flag to backup files with relative paths instead of absolute pathnames. It defaults to the value of "profile_is_relative" for that profile. (Non-relative profiles will show a warning message.)

If the profile is currently in use, it may not be backed up properly.

This version does no munging of the profile data, nor does it store any meta information. See "KNOWN ISSUES" below.

restore_profile
  $res = $moz->restore_profile(
    archive_path => $backup,
    type         => $type,
    name         => $name,
    is_default   => $is_default,
    munge_prefs  => $munge_prefs, # update prefs.js file
  );

  $res = $moz->restore_profile($backup,$type,$name,$is_default);

Restores the profile at $backup. Returns true if successful, false otherwise.

$munge_prefs can only be specified using named parameter calls. If $munge_prefs is true, then it will attempt to correct any absolute paths specified in the prefs.js file.

Warning: this does not check that it is the correct profile type. It will allow you to restore a profile of a different (and possibly incompatible) type.

Potential incompatabilities with extensions are also not handled. See "KNOWN ISSUES" below.

Compatabilty with Earlier Versions

The interface has been changed from version 0.04. Various methods for querying profile information were moved into the Mozilla::ProfilesIni module. Code that was of the form

  $moz->method($type,$name);

should be changed to

  $moz->type($type)->method($name);

The older method calls should still work, but are deprecated and will issue warnings. (Support for them will be removed in some future version.)

See the "type" method for more information.

KNOWN ISSUES

This module is a prototype. Use at your own risk!

Not all of the profile types have been tested, and are implemented based on information gleaned from sources which may or may not be accurate.

The current version of this module only copies files and does little manipulation of any files, except for the profiles.ini and prefs.js to update some pathnames. This means that information specific to a profile on a machine such as extensions and themes is kept as-is, which may not be a good thing if a profile is restored to a different location or machine, or even application.

(By default cache files are excluded from backups; there may be problems if cache files are restored to incompatible applications or machines.)

To Do List

A list of to-do items, in no particular order:

Meta-data

Save meta-data about backups (such as profile type, file locations, platform) so that file-restoration can make the appropriate conversions.

Improved Parameter Checking

Improve parameter type and value checking.

Tests

The test suite needs improved coverage. Sample profiles should be included for more thorough testing.

User-friendly Exclusion Lists

User-friendly exclusion lists (via another module?). Exclusion by categories (privacy protection, E-mail, Bookmarks, etc.).

Standardize Log Messages

Have a standard format (case, puntuation etc.) for log messages. Also standardize error levels (error, alert, critical, etc.).

Possiblly add hooks for internationalisation of messages.

Other

Other "TODO" items marked in source code.

SEE ALSO

Mozilla web site at http://www.mozilla.org.

MozillaZine KnowledgeBase article on Profiles at http://kb.mozillazine.org/Profile.

Mozilla Profile Service source code at http://lxr.mozilla.org/seamonkey/source/toolkit/profile/src/nsToolkitProfileService.cpp.

AUTHOR

Robert Rothenberg <rrwo at cpan.org>

Suggestions and Bug Reporting

Feedback is always welcome. Please use the CPAN Request Tracker at http://rt.cpan.org to submit bug reports.

There is now a SourceForge project for this module at http://mozilla-backup.sourceforge.net/.

LICENSE

Copyright (c) 2005 Robert Rothenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.