Example of setting up mysql automatic backup under ubuntu

  • 2020-05-15 02:19:11
  • OfStack

1. Create a path /mysqldata to save the mysql backup file
#mkdir /mysqldata

2. Create /usr/sbin/bakmysql files
#nano /usr/sbin/bakmysql

Input:
 
#!/bin/sh 
name='date+%Y%m%d' 
mysqldump --all-databases -uroot -p password  > /var/mysqlbak/mysql.sql 


Note: -- all-databases will backup all databases to mysql.sql file under mysqlbak. If -- all-databases is replaced by test, then only test database will be backed up.

3, modify the file properties to make it executable
# chmod +x /usr/sbin/bakmysql

4. Modify /etc/crontab
#nano /etc/crontab

Add:
01 3 * * * root /usr/sbin/bakmysql
Means to perform backups at 3 o 'clock every day.

5. Restart crond
# /etc/init.d/cron restar

To complete.

Related articles: