NAME

mysqlblasy - MySQL backup for lazy sysadmins


SYNOPSIS

mysqlblasy [OPTIONS]


DESCRIPTION

mysqlblasy is a Perl script for automating MySQL database backups. It uses `mysqldump` for dumping mysql databases to the filessytem. It was written with automated usage in mind, e.g. it is very silent during operation and only produces noise on errors/problems. It rotates backups automatically to avoid that the backup disk gets full when the administrator is on vacation (or is lazy). All necessary information for producing backups can be specified in a configuration file, which eliminates the need to hide command line options from the unix process table (like passwords).

Each database gets dumped into a separate file, after which all the dumps get tarred (and optionally compressed) and placed into the specified backup directory. Old files in the backup directory get deleted, and the number you specify newest files are kept (default 7).

Backups get filenames containing the hostname, the date and the time (accuracy: seconds).

The verbosity of the output can be specified using the loglevel configuration key. The recommended value for the loglevel is 2 (WARN).


CONFIGURATION FILE(S)

Configuration files: /etc/mysqlblasy.conf, $HOME/.mysqlblasyrc

Allowed config keys and values:

   backupdir         = directory for placing the backup
   databases         = comma separated list of db's to backup (default all)
   dbusername        = mysql username
   dbpassword        = password for user
   dbhost            = hostname, usually localhost
   loglevel          = NOP(0) ERR(1) WARNING(2) NOTICE(3) INFO(4) DEBUG(5), default 2
   mysqldump         = absolute path to the mysqldump binary (default from $PATH)
   use compression   = yes or no or 1 or 0 (default no)
   compression tool  = see below
   keep              = number of backup files to keep in backupdir
   use syslog        = yes or no or 1 or 0 (default yes)
   tar               = see below

Some of these configuration values may require special attention: 'compression tool' and 'tar' can be specified with their absolute filenames or with only the basename of the executable. If the the specified value cannot be resolved, mysqlblasy does NOT fall back to a default tool!


OPTIONS

-c, --config-file file
Specify an alternative config file. The system-wide configuration is still read, but settings in the specified config file will override the system-wide ones.

-h, --help
Displays this help

-V, --version
Display version and exit


NOTES

mysqlblasy will try to use native command line utilities for tarring and compressing. If no adequate tools are found, it will try to use Perl native routines for tarring and compressing (requires some modules to be installed). The command lines tools are preferred for perfomance reasons (especially memory usage).


LICENSE

This program is distributed under the terms of the BSD Artistic License.


AUTHOR

Copyright (c) 2003-2004 Paul Kremer.


BUGS

Please send patches in unified GNU diff format to <pkremer[at]spurious[dot]biz>


SEE ALSO

DBI, mysqldump, Sys::Syslog, tar, gzip, bzip2, Archive::Tar


Function documentation

bootinit()
bootinit() will initialize some variables as well as environmental variables and load the required perl modules.

cfginit()
cfginit() will initialize the configuration, depending on command line parameters.

try_to_use(use_string)
will eval ``use use_string'' and return undef if it worked. Otherwise returns the exception text.

graceful_die(string message)
graceful_die() will log the given message as error and die.

_logString(mixed message)
_logString() will add debugging information to message and return it. If message is not a string, the variable will be preprocessed by Data::Dumper::Dumper().

_logIt(mixed message, int atlevel)
will format and log the message if atlevel is smaller or equal than the configured loglevel. Returns the logged message if it got logged.

log*(mixed message)
log*() will log the message at the corresponding LOGLEVEL and return the logged message, if it was logged.

_syslog(string message, int atlevel)
_syslog() will send message to the system syslog facility at the specified level if atlevel is smaller or equal than the configured loglevel. Always returns true.

getDbh()
getDbh() will return a DBI connection handle. It uses caching internally so the connection handles will be reused.

getConfigValue(string key)
getConfigValue() returns a string for the given configuration key. It fails on error. Note that this function uses the global config container, which means that configuration needs to be initialized before using this method.

setConfigValue(string key, value)
setConfigValue() sets the value for the given configuration key. It fails on error.

db_prepare(string query)
db_prepare() will prepare the query string for execution. It fails on error.

db_execute(DBI::st handle)
db_execute() will execute the handle and fail on error.

db_do(string query)
db_do() will prepare and execute the string query. It fails on error.

ldb_databases()
ldb_databases() will return the list of databases on the mysql server. It fails on error.

ldb_tables(string database)
ldb_tables() will return the list of tables in the given database.

_system(arrayref params, string out)
_system is a wrapper for the perl system() function. It handles exit codes gracefully and can redirect STDOUT and STDERR of the executed program to the file specified by out. It returns true on success and false on error. It never fails. By default, STDOUT and STDERR are redirected to the null device, to disable output redirection, specify the empty string as output target. _system() never forks a shell (/bin/sh).

_hostname
_hostname() is a safe wrapper for Sys::Hostname::hostname(). It returns the hostname on success and the empty string on failure.

tmpDir()
tmpDir() will return the system-wide temporary directory name. See File::Spec->tmpdir() for details.

workDir()
workDir() will create a temporary directory and return the full path. If the directory already exists, it will choose a different path. If the directory was created from within the same process, it simply returns it. It fails on error.

hostDir()
hostDir() will create a directory inside workDir() which is specific for the current host AND day and return the full path. If the directory was created from within the same process, it simply returns it. It fails on error.

getPath
getPath() will take the environment variable called PATH and parse it into an ARRAY of which it will return a reference. In case the environment variable cannot be parsed to a valid paths, it returns []. Every directory contained will be checked for existence. If no directory can be found, it will return undef.

findInPath(what, [where])
findInPath will try to find the file specified by what in the list of paths specified by where. It checks if the file is existing, readable and executable. If found, it returns the full name of the file, otherwise it returns undef.

fetchFile(string filename)
fetchFile() will read the contents of file filename into a scalar and return it. It fails on error.

getPreferences( config file )
getPreferences() will read preferences from the system wide and private configuration files. It returns a hash reference or fails on error. Optionnally, a config file to be read can be specified as a parameter. If an optional config file is specified, only the system-wide config file is read and then the specified one, while omitting the config file in the user's HOME.

fuFile (string filename, \string buffer)
fuFile() will fetch the content from the file specified by filename, unlink it and put the data into the buffer specified. It will return true on success, false if it could not get the data, and fails if it can't unlink the file.

mydump( {db => string, all => bool, file => string} )
mydump() will dump the database(s) to the specified file.

makeNativeTar( [files], workdir, tarfilename)
makeNativeTar() will create the tar file using native Perl routines/libraries. Returns undef on failure or the filename of the created archive on success. TODO: more POD

makeExternalTar( [files], workdir, tarfilename)
makeNativeTar() will create the tar file using external command line utilities. Returns undef on failure or the filename of the created archive on success. TODO: more POD

TODO

makeTar(directory, [files], workdir, tarfilename)
makeTar() will create the tar file. TODO: more POD

purgeOldFiles(directory, number_of_files_to_keep)
TODO

version
Prints version information and exits.

help
Feeds this script to `perldoc`