mysqlblasy - MySQL backup for lazy sysadmins
mysqlblasy [OPTIONS]
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).
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!
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).
This program is distributed under the terms of the BSD Artistic License.
Copyright (c) 2003-2004 Paul Kremer.
Please send patches in unified GNU diff format to <pkremer[at]spurious[dot]biz>
DBI, mysqldump, Sys::Syslog, tar, gzip, bzip2, Archive::Tar
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)
graceful_die()
will log the given message as error and die.
_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().
_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()
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()
sets the value for the given configuration key. It fails on
error.
db_prepare()
will prepare the query string for execution. It fails on error.
db_execute()
will execute the handle and fail on error.
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()
will return the list of tables in the given database.
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()
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()
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.
fetchFile()
will read the contents of file filename into a scalar and return it.
It fails on error.
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()
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()
will dump the database(s)
to the specified file.
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
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
makeTar()
will create the tar file.
TODO: more POD