Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A simple method of regularly backing up mysql Database by linux

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Here are the detailed steps:

1. Check the disk space:

[root@localhost backup] # df-h File system capacity used used mount point / dev/mapper/centos-root 17G 2.7g 15G 16% / devtmpfs 476M 0476m 0% / devtmpfs 488M 0 488m 0% / dev/shmtmpfs 488M 7.7m 480m 2% / runtmpfs 488M 0488M 0% / sys/fs/cgroup/dev/sda1 1014m 130m 885m 13% / boottmpfs 98M 0 98m 0% / run/user/0 [root@localhost backup] #

Select a suitable disk to store backup files

2. Create a backup directory:

Cd / homemkdir backupcd backup

3. Create a backup Shell script:

Create a backup script (vi bkDatabaseName.sh) in the directory you created

#! / bin/bashmysqldump-uroot-proot rtak > / data/backup/rtak_$ (date +% Y%m%d_%H%M%S). Sqlmysqldump-uroot-proot rtak | gzip > / data/backup/rtak_$ (date +% Y%m%d_%H%M%S) .sql.gz

Note:

Replace bkDatabaseName.sh with an interesting name

You can choose between sql backup and gz backup, or full backup.

User name and password need to be replaced

4. Add executable permissions:

Chmod upright x bkDatabaseName.sh

Test whether the file can be executed properly (. / bkDatabaseName.sh)

Note: (1) if error mysqldump: command not found, execute

Ln-fs / usr/local/mysql/bin/mysqldump / usr/bin (/ usr/local/mysql path is the mysql installation path)

(2) if there are warnings (Warning: Using a password on the command line interface can be insecure.) can be ignored.

(3) check whether the backup sql file is normal and whether it can be imported into the database.

5. Add scheduled tasks

Confirm that crontab is installed:

Execute the crontab command if you report command not found, it indicates that it is not installed

Execute the command:

Crontab-e

Enter the following and save:

* / * * 1 * / data/backup/bkDatabaseName.sh

/ * * 1 * / several * respectively represent the minute, hour, date, month and day of the week to perform the backup operation

For example: backup / 1 * / per minute (tested)

Backup / 00 3 * / (not tested) is performed at 3 am every day.

6. Stop the backup operation

When you do not need a scheduled backup, perform this operation, and the normal process will be completed by step 5.

Crontab-r

Note: clean up sql backups that have been out of date for a long time to prevent the disk from being full.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report