官术网_书友最值得收藏!

Making backups with XtraBackup

XtraBackup is a backup tool from Percona.

Getting ready

The precompiled XtraBackup packages are only available for Linux. Percona provides both YUM and APT repositories.

You can follow the XtraBackup installation instructions on the Percona website available at http://www.percona.com/doc/percona-xtrabackup/. Also, create a backup user by following the instructions in the Creating a backup user recipe.

How to do it...

Let's get started by following the ensuing steps:

  1. Run the following command by changing the --user, --password, and /path/to/backups parts to the correct values:
    sudo innobackupex --user=backupuser \
     --password=p455w0rd /path/to/backups
    
  2. The innobackupex script will call XtraBackup and copy all of the files to a timestamped subdirectory of the specified backup directory. When it has finished, if everything went well, it will print a line similar to the following line of output:
    130729 12:05:12 innobackupex: completed OK!
    

How it works...

The innobackupex script is a wrapper around XtraBackup. By itself, the XtraBackup program only backs up InnoDB and XtraDB databases. When the innobackupex script is used, MyISAM, Aria, and other non-InnoDB tables are also backed up.

There's more...

Backups created by XtraBackup and the innobackupex scripts are not ready to be used to restore a database as is. Backups must be prepared prior to restoring. There are also some things that we need to be aware of when backing up to an NFS-mounted disk.

Restoring from a backup

In order to prepare an XtraBackup backup to be restored, we must first prepare it as follows:

sudo innobackupex --apply-log /path/to/backups

Then, we can restore it with the following command:

sudo innobackupex --copy-back /path/to/backup

As with running the script for the initial backup, look for the completed OK! message at the end of the preparing and restoring steps.

The innobackupex script will refuse to overwrite the files in the data directory, so it must be empty before a restore can happen.

As a final step, we will also likely need to fix permissions on the restored files with something similar to the following command:

sudo chown -R mysql:mysql /var/lib/mysql

XtraBackup and NFS

When backing up to an NFS-mounted volume, check to make sure that it is mounted with the sync option. Data may appear corrupt if our NFS volume is mounted with the async option. Refer to the XtraBackup documentation for more information.

主站蜘蛛池模板: 托克逊县| 惠东县| 太谷县| 伊春市| 内江市| 开封县| 车致| 宾阳县| 通河县| 延安市| 鄂托克前旗| 怀柔区| 崇州市| 白城市| 六枝特区| 临江市| 长春市| 衡阳市| 股票| 深州市| 苏尼特右旗| 绵阳市| 隆德县| 鹤壁市| 广水市| 龙岩市| 都江堰市| 广西| 景谷| 永仁县| 盐池县| 常宁市| 海宁市| 罗源县| 建平县| 容城县| 雷波县| 涟水县| 二手房| 内丘县| 岳阳县|