Professional Documents
Culture Documents
Backup and Recovery
Backup and Recovery
Logical backup
Physical backup
Local backup
Remote backup
Full backup
Incremental backup
When do we need backup?
Hardware Failures
A system crash may cause some of the data in the
database to be lost. Hardware failure leads to data loss.
User/Application Failure
Log files
• For incremental backups
• Point in time recovery
Configuration
–
information
• /etc/my.cnf
• Cron jobs
When should backups be
performed?
On a regular basis
Not during high usage peaks (off hours)
Static data can be backed up less frequently
Schedule it at particular time intervals
Where to store backup?
• On the database server
On a separate file system/volume or hard disk drive
• Backed up to tape/disk
• Choose multiple locations
Database Backup Methods
• Backup programs
Mysqldump
Mysqlhotcopy
• Copying table files (*.frm, *.MYD, and *.MYI files)
• Delimited-Text files
• Incremental Backups using Binary Log
• Backups using Replication Slaves
Using mysqldump for backups
Mysqldump is a backup program originally written by Igor
Romanenko.
Used to dump a database or a collection of databases for backup
or transfer to another server(not necessarily MySQL).
Mysqldump writes SQL statements to the standard output.
This output consists of CREATE statements to create dumped
objects (databases, tables, stored routines etc) and INSERT
statements to load data into tables.
The output can be saved in a file and reloaded later using mysql to
recreate the dumped objects.
Options are available to modify the format of the SQL statements,
and to control which objects are dumped.
Generates files in CSV, other delimited text, or XML format also.
Backup using mysqldump
Set of one or more tables
$ mysqldump -u [uname] -p[pass] db_name table1 > table_backup.sql
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
All databases
$ mysqldump -u [uname] -p[pass] –all-databases > all_db_backup.sql
An entire MySQL
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
Remote Backup
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql
Restore backup from mysqldump
By default, the server creates binary log files in the data directory.
The binary log files provide you with the information you need to replicate changes to
the database that are made subsequent to the point at which you performed a
backup.
To see a listing of all binary log files
mysql> SHOW BINARY LOGS;
An incremental backup only backs up data that changed since the previous backup.
Start the server with the --log-bin option to enable binary logging.
mysqlbinlog utility converts the events in the binary log files from binary format to text
so that they can be executed or viewed. mysqlbinlog has options for selecting
sections of the binary log based on event times or position of events within the log.
Copy to the backup location,all binary logs from the moment the last backup was
taken to the last but one.
Enable binary logging
Configure mysql to do binary logging.
Edit : /etc/mysql/my.cnf:
Add : log-bin = mybinlog
Specify which databases to do binary logging for, or which databases NOT to
do binary logging for.
C:\xampp\mysql\bin>mysqlbinlog --start-datetime="2014-06-01
10:31:44" C:\xampp\mysql\data\binlog\bin-log.000001 > sql.txt
●
• The synchronised binary logs are used to extract
queries issued between the backup and now.
• If recovering data lost due to unwise queries,dont issue them
again.
• http://dev.mysql.com/doc/refman/5.6/en
• http://www.techflirt.com/
• http://planet.mysql.com/
THANK YOU