innobackupex incremental online backup of InnoDB hot backup of the database

innobackupex incremental online backup of InnoDB hot backup of the database

What is incremental backup? The principle is what?

Incremental backups are based on the newly added content to back up after the last backup , full backup in terms of advantages compared to less content backup time is short, can save disk space. But in comparison to a full backup in terms of reliability has decreased, not based on lack of incremental backup interval full backup backup package, a full backup is recommended time intervals not greater than one week under normal circumstances, if the database is very large personal recommendations three days to seven days complete backup once, incremental backups during the day. If the database is small then a full backup is the safest choice every day.

What incremental backup principle? How did he record the position of the last backup?

First, InnoDB, each page are recorded LSN information, whenever data is changed, the page will automatically increase LSN, xtrabackup incremental backup is performed based on this principle. We incremental backup must be a full backup under the premise of a xtrabackup_checkpoints file will be generated in the backup directory after a full backup on record to_lsn = xxxx, the next backup will start from here to the end of each incremental backup needs a directory name on the specified incremental backup, incremental backups every so from the end, when restoring the full and incremental backups and incremental backups 1 2 merge and then merge again with the merger until the last incremental backup N after an incremental completion of the merger, the resulting data is a full backup, then restore the data integrity.

  • Firstly I do a full backup of the database, the database does not specify any time most backup subdirectory name.

    innobackupex -uroot -p12345 --user root --password 12345 /fullbackup --no-timestamp
  • Create a new library table simulation simulate new user-generated data.

    mysql -uroot -p12345 -e "create database new1;"
    mysql -uroot -p12345 -e "create table new1.newtable1 (id int(10));"
    for i in {1..100};do mysql -uroot -p12345 -e "insert into new1.newtable1 values($i);" ;done
  • Then incremental backups, you need to specify directories and directory --incremental be --incremental-basedir full backup incremental backup.

    innobackupex --user root --password 12345 --incremental /increback --incremental-basedir /fullbackup --no-timestamp
  • And then to simulate user-generated data to the newly created table.

    for i in {101..201};do mysql -uroot -p12345 -e "insert into new1.newtable1 values($i);" ;done
  • Then use the incremental backup backup to note here is that --incremental-basedir specified directory is the last incremental backup of the directory.

    innobackupex --user root --password 12345 --incremental /increback2 --incremental-basedir /increback --no-timestamp
  • Since the end of the last backup position to compare the new backup, look at the first position to the last incremental backup.

    ---------从0备份到4158368-----------------------------------------
    backup_type = full-backuped
    from_lsn = 0
    to_lsn = 4158368
    last_lsn = 4158377
    compact = 0
    recover_binlog_info = 0
    ---------从4158368备份到4197299-----------------------------------
    backup_type = incremental
    from_lsn = 4158368
    to_lsn = 4197299
    last_lsn = 4197308
    compact = 0
    recover_binlog_info = 0
    --------从4197299备份到4232734------------------------------------
    backup_type = incremental
    from_lsn = 4197299
    to_lsn = 4232734
    last_lsn = 4232743
    compact = 0
    recover_binlog_info = 0
    ----------------------------------------------------------------
    #就和之前说的一样每次备份完成后的重点都是下一次备份的起点。
  • Open data is ready to resume ( resume normally go to another machine, then the backup interval to recover the missing part of the data through binlog, I'm here on the backup-related files directly deleted directory restored. )

  • The first thing is to complete the first backup and incremental backup and then merge with the second incremental backup and then merge with the N incremental backup consolidation.

    innobackupex --apply-log --redo-only /fullbackup
    innobackupex --apply-log --redo-only /fullbackup --incremental-dir /increback
    innobackupex --apply-log --redo-only /fullbackup --incremental-dir /increback2
  • After the database backup integration service stopped package all the files in the database backup to its default path / home directory and then go delete all of the following things.

    systemctl stop mysqld && tar -zcvPf /home/mysqldatadir.tar.gz /var/lib/mysql && rm -rf /var/lib/mysql/*
  • Then copy recovery.

    innobackupex --copy-back /fullbackup/
  • Because the root user is using all of the owner and group are root, it needs to be changed mysql.

    chown -R  mysql:mysql /var/lib/mysql
  • Whether to start the service and check the data properly.

    systemctl start mysqld
    mysql -uroot -p12345 -e "select * from new1.newtable1;"
  • Part of the data loss can occur during recovery by combining binlog.

Guess you like

Origin www.cnblogs.com/lqinghua/p/11682097.html