SoFunction
Updated on 2025-03-09

MySQL automatic incremental backup example method (local backup and remote backup)

1. Local backup
Write an automatic backup script:
vim /var/lib/mysql/autobak
The content is as follows:

Copy the codeThe code is as follows:

cd /data/home/mysqlbak
rq=` date +%Y%m%d `
/usr/local/mysql/bin/mysqldump sqldb --flush-logs -uroot -p123456 --opt > 777city_$

Save and exit.

chmod -777  /var/lib/mysql/autobak

crontab -e
00 00 * * *  /var/lib/mysql/autobak
Autobak scripts are automatically executed in the early hours of the night every night.
/etc//crontab restart

Execute the script manually to see the effect.
./var/lib/mysql/autobak
ls /data/home/mysqlbak

Check the file size
du -sh /data/home/mysqlbak/

2. Remote backup of the database
Remote backup command:

Copy the codeThe code is as follows:

/usr/local/mysql/bin/mysqldump sqldb --flush-logs -uroot -p'123456' -h'10.241.92.172' --opt > /root/

Automatic remote backup:
Backup on the ip:67 machine, the mysql database of the ip:172 server
Operation on the machine at ip:67:
1. Write an automatic backup script:
vim /var/lib/mysql/autobak
The content is as follows:

Copy the codeThe code is as follows:

cd /data/home/mysqlbak
rq=` date +%Y%m%d `
/usr/local/mysql/bin/mysqldump sqldb --flush-logs -uroot -p'123456' -h'10.241.92.172' --opt > 777city_$

Save and exit.

chmod -R 777  /var/lib/mysql/autobak

crontab -e
00 00 * * *  /var/lib/mysql/autobak
Autobak scripts are automatically executed in the early hours of the night every night.
/etc//crontab restart

Execute the script manually to see the effect.
/var/lib/mysql/autobak
ls /data/home/mysqlbak

Check the file size
du -sh /data/home/mysqlbak/