Mysql---server regularly backs up the database

Linux regularly backs up mysql:

Check the disk space:

df -h   
查看磁盘
[root@iZ2olwfa4l2rr9Z ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        900M   32K  900M   1% /dev
tmpfs           915M     0  915M   0% /dev/shm
tmpfs           915M  484K  915M   1% /run
tmpfs           915M     0  915M   0% /sys/fs/cgroup
/dev/vda1        40G  6.7G   34G  17% /
tmpfs           183M     0  183M   0% /run/user/0

Create a backup directory:

cd dev
mkdir backup

crw-r--r-- 1 root root     10, 235 Nov  2 12:32 autofs
drwxr-xr-x 2 root root         160 Nov  7 13:44 backup

Create a backup shell script

vi test.sh

The content of test.sh:

#!/bin/bash
mysqldump -uroot -p(密码) test > /dev/backup/test_$(date +%Y%m%d_%H%M%S).sql
#!/bin/bash
mysqldump -uroot -p(密码) test | gzip > /dev/backup/test_$(date +%Y%m%d_%H%M%S).sql.gz

Correspond to our account, password, database

Add script executable permissions:

chmod u+x test.sh

Test whether the script can run normally:

./test.sh

Add tasks to execute scripts regularly;

crontab -e

Edit content:

0 */2 * * * * /home/backup/test.sh

Set to execute once every 2 hours;

Insert picture description here

Generate files;

Guess you like

Origin blog.csdn.net/qq_43549291/article/details/109678434