Uploaded on Mar 3, 2023
It can be time-consuming to take full database backup every time in MySQL. Here is how to do incremental backup in MySQL using binary log. Visit https://techimbo.com/how-to-do-incremental-backup-in-mysql-using-binary-log/ #mysql #backup #database
How-to-Do-Incremental-Backup-in-MySQL
How to Do Incremental Backup in MySQL Using Binary Log Install MySQL Open terminal and run the following command to install latest MySQL version. If it is already installed on your system, you can skip this step. $ apt-get install mysql-server -y During installation, you will be asked to set root password, and may also see some prompts. Enter password of your choice, and enter yes for prompts. After you install MySQL, run the following commands to start server and enable it to autostart during system reboot. $ systemctl start mysql $ systemctl enable mysql Enable Binary Logging Open MySQL configuration file in a text editor. $ vi /etc/mysql/mysql.conf.d/mysqld.cnf Add/modify the following lines to look as below. log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 Here we specify log location for binary log and also the number of days after which it expires. Save and close the file. Restart MySQL server to apply changes. $ systemctl restart mysql Take Full Backup of Database Run the following command to take full backup of your database. $ mysqldump -uroot -p --all-databases --single-transaction --flush-logs --master-data=2 > full_backup.sql Now if you check out your log file location $ ls -l /var/log/mysql/ Take Incremental Backup To take incremental backup, you need to flush the binary logs and save binary logs created from last full backup. $ mysqladmin -uroot -p flush-logs It will close mysql-bin.000002 and create new file mysql-bin.000003. You can check it in the folder location containing binary logs. Restore Database from Incremental Backup Now to restore database from incremental backup, we create a new database. mysql> create database mydb; mysql> exit; Next, we populate the new database using the full backup file. $ mysql -u root -p mydb < full_backup.sql At this point if you view the records in your database, it will not contain the incremental changes made after full backup taken earlier. For this purpose, run the following command that will analyze the binary log for incremental changes and add them to your new database mydb. $ mysqlbinlog /var/log/mysql/mysql-bin.000002 | mysql -uroot -p mydb Thank You Visit for details https://techimbo.com/how-to-do-incremental-backup-in-mys ql-using-binary-log/
Comments