Sean P. Quinlan > DBA-Backup-0.2_1 > DBA::Backup

Download:
DBA-Backup-0.2_1.tar.gz

Dependencies

Annotate this POD

Related Modules

MySQL::Backup
more...
By perlmonks.org
Module Version: 0.2_1   Source  

NAME ^

DBA::Backup - Core module for managing automated database backups.

SYNOPSIS ^

NOTICE! This is currently a broken partial port from the origal working MySQL specific module. I hope to have the port finished and a functional version uploaded soon. Email me or the list for more information.

The mailing list for the DBA modules is perl-dba@fini.net. See http://lists.fini.net/mailman/listinfo/perl-dba to subscribe.

  use DBA::Backup;
  
  my $dba = new DBA::Backup(%params);
  die "Can't initiate backups: $dba" unless ref $dba;
  
  $dba->run(%conf_overides);
  $dba->log_messages();
  $dba->send_email_notification();

new() ^

Create new DBA::Backup object. Use this object to initiate backups.

OPTIONS:

CONF_FILE: Location of configuration file to use. Default is /etc/dba-backup.yml. Please keep in mind that conf files for any specific servers to be backup will need to be in the same location.

LOG_FILE: Location to write process log file.

BACKUP: If true will force full database backups.

ADD_DATABASES: Specify additional databases to be backed up. ** broken

usage() ^

    Prints an usage message for the program on the screen and then exits.

run() ^

    This is where most of the work in the program is done.
    It logs some messages to the log file and invokes the subroutines
    for database backup and log backup and rotation.

_test_create_dirs ^

        Test for the existence and writeability of specified directories.
        If the directories do not exist, attempt to create them.  If unable
        to create writeable directories, fail with error.

_rotate_dump_dirs() ^

        The dump directories contain output from both the full, weekly mysql
        dump as well as the incremental binary update logs that follow the
        dump (possibly multiple binlogs per day).  Rotate these directory 
        names to conform to convention:

          [dump_dir]/00/  - most recent dump
          [dump_dir]/01/   - next most recent
          ...
          [dump_dir]/_NN/       - oldest

        Where N is [dump_copies] - 1 (in the config file).  [dump_dir]/new/
        is a temporary directory created from _backup_databases.  This will
        be renamed 00/, 00/ will be renamed 01/, and so on.

_tidy_dump_dirs() ^

        The dump directories contain output from both the full, weekly mysql
        dump as well as the incremental binary update logs that follow the
        dump (possibly multiple binlogs per day).  Sometimes a user might
        delete a directory between backup runs (particularly if it has bad
        dumps).

        This function is intended to be run before backups start.  It will
        Attempt to make directory names to conform to convention:

          [dump_dir]/00/  - most recent dump
          [dump_dir]/01/   - next most recent
          ...
          [dump_dir]/NN/        - oldest

        If there are missing directories, _tidy_dump_dirs will create a
        directory to take its place, such that 00/ should always exist
        and there should be no gaps in the numbering of old directories.  In
        other words, N+1 should be the total number of directories in [dump_dir].

        If there are no gaps to begin with, _tidy_dump_dirs does not rename
        anything.

        This function will also delete any xx directories that exceed the
        [dump_copies] config variable.

        It will never touch [dump_dir]/new/.  It will never modify the contents
        of any of these subdirectories (unless its deleting the whole subdir).

        It will create [dump_dir] and [dump_dir]/00/ if they do not exist.

send_email_notification() ^

        Sends the data from the 00 run of the program 
        which gets stored in the log file by email. The exact 
        behaviour for this subroutine is controlled by the 
        varibles in [mail-setup] section in the config file

INSTALLATION ^

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES ^

This module requires these other modules and libraries:

  Mail::Sendmail # if you want email reports
  YAML
  Sys::Hostname
  File::Copy
  File::Path

DESCRIPTION ^

Manages rotation of mysql database logs and database backups. Reads information on which databases to back up on what days for the week from the configuration file. If no file is specified, it will look for one at /etc/mysql-backup.conf. If no configuration file is found program will exit with a failure.

This program assumes a MySQL 4.0.x server that is at least 4.0.10. It will likely work with current 1.23.xx server, but that has not been tested. Please let the maintainers know if you use this tool succesfully with other versions of MySQL or Perl so we can note what systems it works with.

The expected usage of this program is for it to be run daily by a cron job, at a time of day convienient to have the backups occur. This program uses the administrative tools provided with MySQL (mysqladmin and mysqldump) as well as gzip for compression of backups.

Every time this program is run it will flush the MySQL logs. The binary update log will be moved into /path/to/dump/dir/00. Error log and slow query log files are rotated only if they exceeded the size limit specified in the confguration file.

If it is run on a day when full database backups are specified, then all databases specified in the config file are dumped and written to the directory specified in dump_dir variable in the config file. If there are no problems with this operation, previous full backups from dump_dir/00 are moved to directory dump_dir/01 and all the files in dump_dir/01 (full database backups and log files) are deleted from it or moved to dump_dir/02 etc. to the archival depth specified in the config file. This way there always [dump_copies] full database backups - one in 00/ and [dump_copies]-1 in the xx directories.

Detailed information about the different configuration parameters can be found in the comments in the configuration file

log-slow-queries log-long-format log-bin # required log-error # should be required?

OPTIONS ^

logfile

Filename for logging backup proceedure. Overrides conf file.

add_databases

Additional databases to back up. These will be backed up in addation to any databases specified in the conf file. Note - this adds databases to the list of those to be backed up. If the program is being run on a day when database backups are not scheduled, the extra databases specified will not be backed up.

backup

If present this option forces full database backups to be done, even if not normally scheduled.

help

Outputs this help file.

d

** NOT IMPLIMENTED **

Turn on debugging. Optionally takes a filename to store debugging and any error messages to.

v

** NOT IMPLIMENTED **

Increases debugging vebosity. If three or more v's provided (-v -v -v) than program will exit on warnings.

TO DO ^

Impliment debugging output options.

Streamline config process - can we avoid using multiple config files?

Support multiple servers of the same type.

HISTORY ^

0.1

Partial port from original MySQL specific version.

0.1.1

Some more work on getting port working and some comments. Early release for boston.pm mailing list.

0.1.2

Improved configuration handling allowing multiple servers per RDBMS type. Draft example of calling extension method and providing only server specific conf hash explicitly instead of making extension find it.

SEE ALSO ^

The mailing list for the DBA modules is perl-dba@fini.net. See http://lists.fini.net/mailman/listinfo/perl-dba to subscribe.

dba-backup.yml dba-backup

AUTHOR ^

Sean P. Quinlan, <gilant@gmail.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2004 by Sean P. Quinlan

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: