WARNING: THIS PROGRAM IS STILL IN BETA. Comments/patches welcome.
DESCRIPTION
mysqlhotcopy is designed to make stable copies of live MySQL databases.
Here ``live'' means that the database server is running and the database
may be in active use. And ``stable'' means that the copy will not have
any corruptions that could occur if the table files were simply copied
without first being locked and flushed from within the server.
OPTIONS
--checkpoint checkpoint-table
As each database is copied, an entry is written to the specified
checkpoint-table. This has the happy side-effect of updating the
MySQL update-log (if it is switched on) giving a good indication of
where roll-forward should begin for backup+rollforward schemes.
The name of the checkpoint table should be supplied in database.table format.
The checkpoint-table must contain at least the following fields:
time_stamp timestamp not null
src varchar(32)
dest varchar(60)
msg varchar(255)
--record_log_pos log-pos-table
Just before the database files are copied, update the record in the
log-pos-table from the values returned from ``show master status'' and
``show slave status''. The master status values are stored in the
log_file and log_pos columns, and establish the position in the binary
logs that any slaves of this host should adopt if initialised from
this dump. The slave status values are stored in master_host,
master_log_file, and master_log_pos, and these are useful if the host
performing the dump is a slave and other sibling slaves are to be
initialised from this dump.
The name of the log-pos table should be supplied in database.table format.
A sample log-pos table definition:
CREATE TABLE log_pos (
host varchar(60) NOT null,
time_stamp timestamp(14) NOT NULL,
log_file varchar(32) default NULL,
log_pos int(11) default NULL,
master_host varchar(60) NULL,
master_log_file varchar(32) NULL,
master_log_pos int NULL,
PRIMARY KEY (host)
);
--suffix suffix
Each database is copied back into the originating datadir under
a new name. The new name is the original name with the suffix
appended.
If only a single db_name is supplied and the --suffix flag is not
supplied, then ``--suffix=_copy'' is assumed.
--allowold
Move any existing version of the destination to a backup directory for
the duration of the copy. If the copy successfully completes, the backup
directory is deleted - unless the --keepold flag is set. If the copy fails,
the backup directory is restored.
The backup directory name is the original name with ``_old'' appended.
Any existing versions of the backup directory are deleted.
--keepold
Behaves as for the --allowold, with the additional feature
of keeping the backup directory after the copy successfully completes.
--flushlog
Rotate the log files by executing ``FLUSH LOGS'' after all tables are
locked, and before they are copied.
--resetmaster
Reset the bin-log by executing ``RESET MASTER'' after all tables are
locked, and before they are copied. Usefull if you are recovering a
slave in a replication setup.
--resetslave
Reset the master.info by executing ``RESET SLAVE'' after all tables are
locked, and before they are copied. Usefull if you are recovering a
server in a mutual replication setup.
--regexp pattern
Copy all databases with names matching the pattern
db_name./pattern/
Copy only tables matching pattern. Shell metacharacters ( (, ), |, !,
etc.) have to be escaped (e.g. \). For example, to select all tables
in database db1 whose names begin with 'foo' or 'bar':
UNIX domain socket to use when connecting to local server
--noindices
Don\'t include index files in copy. Only up to the first 2048 bytes
are copied; You can restore the indexes with isamchk -r or myisamchk -r
on the backup.
--method=#
method for copy (only ``cp'' currently supported). Alpha support for
``scp'' was added in November 2000. Your experience with the scp method
will vary with your ability to understand how scp works. 'man scp'
and 'man ssh' are your friends.
The destination directory _must exist_ on the target machine using the
scp method. --keepold and --allowold are meeningless with scp.
Liberal use of the --debug option will help you figure out what\'s
really going on when you do an scp.
Note that using scp will lock your tables for a _long_ time unless
your network connection is _fast_. If this is unacceptable to you,
use the 'cp' method to copy the tables to some temporary area and then
scp or rsync the files at your leisure.
-q, --quiet
be silent except for errors
--debug
Debug messages are displayed
-n, --dryrun
Display commands without actually doing them
WARRANTY
This software is free and comes without warranty of any kind. You
should never trust backup software without studying the code yourself.
Study the code inside this script and only rely on it if you believe
that it does the right thing for you.
Patches adding bug fixes, documentation and new features are welcome.
Please send these to internals@lists.mysql.com.
TO DO
Extend the individual table copy to allow multiple subsets of tables
to be specified on the command line:
mysqlhotcopy db newdb t1 t2 /^foo_/ : t3 /^bar_/ : +
where ``:'' delimits the subsets, the /^foo_/ indicates all tables
with names begining with ``foo_'' and the ``+'' indicates all tables
not copied by the previous subsets.
newdb is either another not existing database or a full path to a directory
where we can create a directory 'db'
Add option to lock each table in turn for people who don\'t need
cross-table integrity.
Add option to FLUSH STATUS just before UNLOCK TABLES.
Add support for other copy methods (eg tar to single file?).
Add support for forthcoming MySQL ``RAID'' table subdirectory layouts.
AUTHOR
Tim Bunce
Martin Waite - added checkpoint, flushlog, regexp and dryrun options
Fixed cleanup of targets when hotcopy fails.
Added --record_log_pos.
RAID tables are now copied (don't know if this works over scp).
Ralph Corderoy - added synonyms for commands
Scott Wiersdorf - added table regex and scp support
Monty - working --noindex (copy only first 2048 bytes of index file)
Fixes for --method=scp
Ask Bjoern Hansen - Cleanup code to fix a few bugs and enable -w again.
Emil S. Hansen - Added resetslave and resetmaster.
Jeremy D. Zawodny - Removed depricated DBI calls. Fixed bug which
resulted in nothing being copied when a regexp was specified but no
database name(s).