In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the method of linux to achieve regular backup mysql database, I hope you will learn a lot after reading this article, let's discuss it together!
1 、 View disk space: [root@localhost backup] # df-h File system capacity available available mount point / dev/mapper/centos-root 17G 2.7g 15G 16% / devtmpfs 476m 0476m 0% / devtmpfs 488m 0488m 0% / dev/shmtmpfs 488m 7.7m 480m 2% / runtmpfs 488M 0 488m 0% / sys/fs/cgroup/dev/sda1 1014M 130M 885M 13% / boottmpfs 98M 098m 0% / run/user/0 [root@localhost backup] #
Select a suitable disk to store backup files
2. Create backup directory: cd / homemkdir backupcd backup3, create 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 Ubunx 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.
After reading this article, I believe you have a certain understanding of the method of linux to achieve regular backup of mysql database, want to know more about it, welcome to follow the industry information channel, thank you for reading!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
Syntax: select * from TABLE where dbms_lob.instr (CLOB_COLUMN,' matching criteria', 1) < > 0
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.