Downloading a Backup File and Restoring Data from It
You can download a backup file and restore data from it.
Backup data cannot be restored to local databases that run the Windows operating system.
Prerequisites
When you restore data from backup files to self-built MySQL databases, ensure that the target MySQL version is later than or equal to the original MySQL version.
During data restoration, run the following command to view the restoration process:
ps -ef | grep mysql
Procedure
- Download the qpress program and upload it to the ECS for installation.
Download qpress-11-linux.x64.tar from the website and upload it to the ECS.
tar -xvf qpress-11-linux-x64.tar
mv qpress /usr/bin/
- Download the XtraBackup software and upload it to the ECS for installation.
- For MySQL 5.6 and 5.7, download XtraBackup 2.4.9 or later versions.
- For MySQL 8.0, download XtraBackup 8.0 or later versions.
Download XtraBackup from the website and upload it to the ECS. The following uses percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm as an example.
rpm -ivh percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm --nodeps --force
- On the ECS, decompress the full backup file that has been downloaded.
- Create a temporary directory backupdir.
mkdir backupdir
- Decompress the package.
xbstream -x -p 4 < ./Full backup file.qp -C ./backupdir/
- For MySQL 5.6 and 5.7, run innobackupex --parallel 4 --decompress ./backupdir.
- For MySQL 8.0, run xtrabackup --parallel 4 --decompress --target-dir=./backupdir.
find ./backupdir/ -name '*.qp' | xargs rm -f
- Create a temporary directory backupdir.
- Apply the log.
- For MySQL 5.6 and 5.7, run innobackupex --apply-log ./backupdir.
- For MySQL 8.0, run xtrabackup --prepare --target-dir=./backupdir.
- Back up data.
- Stop MySQL database services.
For MySQL 5.7, run the following command to stop MySQL database services:
/bin/systemctl stop mysqld.service
- Back up the original database directory.
- Create a new database directory and change the permissions.
chown mysql:mysql /var/lib/mysql/data
- Stop MySQL database services.
- Copy the full backup file and modify the directory permissions.
- For MySQL 5.6 and 5.7, run innobackupex --defaults-file=/etc/my.cnf --copy-back ./backupdir.
- For MySQL 8.0, run xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=./backupdir.
chown -R mysql:mysql /var/lib/mysql/data
- Start the database.
service mysql start
For MySQL 5.7, run the following command to start the database:
/bin/systemctl start mysqld.service
- Log in to the database and view the restoration result.
mysql -u -root
show databases
Figure 1 Viewing the restoration result
Last Article: Using RDS for MySQL to Set Up Discuz!
Next Article: Description of innodb_flush_log_at_trx_commit and sync_binlog
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.