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

How mysql creates backups

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

The following content mainly brings you how to create a backup of mysql. The knowledge mentioned here, which is slightly different from books, is summarized by professional and technical personnel in the process of contact with users, and has a certain value of experience sharing. I hope to bring help to the majority of readers.

Backup process

Create a backup directory

$cd ~ $mkdir backup$ cd backup

Create a backup Shell script:

Vim DatabaseNameBackup.sh

#! / bin/bash

Find ~ /-name DBName*-type f-ctime + 5-exec rm-f {}\

Mysqldump-uusername-ppassword DBName | gzip > ~ / DBName$ (date +% Y%m%d_%H%M%S) .sql.gz

Note:

Replace username with the actual user name

Replace password with the actual password

Replace DBName with the actual database name

Add executable permissions

Chmod upright x DatabaseNameBackup.sh

Edit the / etc/crontab file directly, that is, vi / etc/crontab, and add the appropriate tasks. Crond

Is a command that linux uses to execute the program on a regular basis. When the operating system is installed, this task scheduling command is started by default. The crond command checks regularly every minute to see if there is any work to be performed, and if there is any work to be performed, it will be performed automatically. You can start and shut down the service in the following ways:

/ sbin/service cron start / / start the service

/ sbin/service cron stop / / shut down the service

/ sbin/service cron restart / / restart the service

/ sbin/service cron reload / / reload the configuration

Crontab command options

The cron service provides a crontab command to set the cron service. Here are some parameters and instructions for this command:

Crontab-u / / sets a user's cron service. Generally, root users need this parameter when executing this command.

Crontab-l / / lists the details of a user's cron service

Crontab-r / / Delete cron services without users

Crontab-e / / Edit a user's cron service

For example, root checks its cron settings: crontab-u root-l

For example, root wants to delete the cron setting of fred: crontab-u fred-r

When editing a cron service, there are some formats and conventions for editing. Enter: crontab-u root-e

Example of a scheduled task

Crontab format: commands to be run in time-sharing, day, month and week

Column 1 minute 1: 59 column 2 hour 1: 23 (0 for midnight) column 3, day 1: 31, column 4, month 1: 12, column 5, week 0,6 (0 means Sunday) column 6 commands to run

Crontab example

5 * ls / / specify ls command 30 5 * ls / / specify ls command 30 7 8 * * ls at 5:30 every hour / / specify ls command 305 8 6 * ls / / specify ls order 306 * * 0 ls / / specify that ls order be executed at 5:30 on June 8 of each year at 7:30 on the 8th of each month [Note: 0 means Sunday [Note: 0] 1 means Monday, and so on, it can also be expressed in English, sun means Sunday, mon means Monday, etc.] 30 3 10 ls 20 * / execute the ls order at 3:30 on the 10th and 20th of each month [Note: " "used to connect multiple discontiguous periods] 25 8-11 * ls / / execute the ls command at the 25th minute from 8 to 11:00 every day [Note:"-"used to connect consecutive periods] * / 15 * ls / / execute the ls command every 15 minutes [that is, execute the ls command on the 015 30 45 60 minute of each hour] 30 6 * / 10 * * ls / / in the middle of each month Execute the ls command at 6:30 every 10 days [that is, the ls command is executed at 6:30 on the 1st, 11th, 21st and 31st of each month. ] 507 * root run-parts / etc/cron.daily / / execute all executables in the / etc/cron.daily directory at 7:50 every day as root [Note: the run-parts parameter indicates that all executables in the following directory will be executed. ]

Add scheduled task

Crontab-e01 3 * root/home/backup/DatabaseName.sh

Indicates that a backup is performed at 3 o'clock every day

For the above about how to create mysql backup, if you need to know more, you can continue to follow our industry promotion. If you need professional solutions, you can contact the pre-sales and after-sales on the official website. I hope this article can bring you some knowledge updates.

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

Internet Technology

Wechat

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

12
Report