1. Local Backup
To write an automatic backup script:
Vim/var/lib/mysql/autobak
The contents are as follows:
Copy Code code as follows:
Cd/data/home/mysqlbak
rq= ' Date +%y%m%d '
/usr/local/mysql/bin/mysqldump sqldb--flush-logs-uroot-p123456--opt > 777city_$rq.sql
Save exit.
Chmod-777/var/lib/mysql/autobak
Crontab-e
* * * */var/lib/mysql/autobak
The Autobak script is automatically executed every evening early in the morning.
/etc/init.d/crontab restart
Manually execute the script to see the effect.
./var/lib/mysql/autobak
Ls/data/home/mysqlbak
View the bottom file size
Du-sh/data/home/mysqlbak/777city11.sql
2. Remote BACKUP Database
Remote backup command:
Copy Code code as follows:
/usr/local/mysql/bin/mysqldump sqldb--flush-logs-uroot-p ' 123456 '-h ' 10.241.92.172 '--opt >/root/777city22.sql
Automatic Remote backup:
Back up the MySQL database of the ip:172 server on the ip:67 machine
To operate on a ip:67 machine:
1, write automatic backup script:
Vim/var/lib/mysql/autobak
The contents are as follows:
Copy Code code 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_$rq.sql
Save exit.
Chmod-r 777/var/lib/mysql/autobak
Crontab-e
* * * */var/lib/mysql/autobak
The Autobak script is automatically executed every evening early in the morning.
/etc/init.d/crontab restart
Manually execute the script to see the effect.
/var/lib/mysql/autobak
Ls/data/home/mysqlbak
View down file size
Du-sh/data/home/mysqlbak/777city11.sql