search
HomeDatabaseMysql TutorialExamples to explain how to use crontab to back up MySQL regularly

Use the system crontab to execute backup files regularly and save the backup results by date to achieve the purpose of backup.


1. Create the path to save the backup file /MySQLdata


#mkdir /mysqldata


2. Create the /usr/sbin/bakmysql file


#vi /usr/sbin /bakmysql


Enter


Note: The ` symbol is the symbol above the TAB key, not the


to the left of ENTER. There must also be a space after the date. Drq = `date +%y%m%d's `Tar ZCVF/Mysqldata/Mysql $rq.tar.gz/var/lib/mysql


rq=` date +%Y%m%d `

mysqldump --all-databases -u root -p password> /mysqldata/mysql$rq.sql

/var/lib /mysql is the directory of your database files. For some users, it is /usr/local/mysql/data. It may be different for everyone. /mysqldata/ represents the directory where backup files are saved. Everyone can also choose this according to their own requirements. Do.

3. Modify the file attributes to make it executable

# chmod +x /usr/sbin/bakmysql

4. Modify /etc/crontab

#vi / etc/crontab

Add

01 3 * * * root /usr/sbin/bakmysql

means to perform backup at 3 o'clock every day

02 * * * * root /usr/sbin/bakmysql

Back up every second minute of every hour


5. Restart crond


# /etc/rc.d/init.d/crond restart


Finish.

So you can see such a file in /mysqldata every day

mysql20070929.tar.gz

Just download it directly.

The above is an example of how to use crontab to regularly back up MySQL. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
crontab定时任务不执行的一些原因,你知道吗?crontab定时任务不执行的一些原因,你知道吗?Mar 09, 2024 am 09:49 AM

crontab定时任务不执行的一些缘由总结更新时间:2019年01月09日09:34:57作者:田野上的希望这篇文章主要给你们总结介绍了关于crontab定时任务不执行的一些缘由,对每种可能发生的诱因都给出了解决方式,对遇见这个问题的同事们具有一定的参考学习价值,须要的同学们下边随着小编来一起学习学习吧序言近来在工作中遇见了一些问题,crontab定时任务竟然不执行,后来我在网上找的时侯发觉网上主要说了这5个诱因:1crond服务未启动crontab不是Linux内核的功能,而是依赖一个cron

如何使用Systemd和Crontab在Linux系统中实现任务的并行执行如何使用Systemd和Crontab在Linux系统中实现任务的并行执行Sep 26, 2023 pm 06:37 PM

如何使用Systemd和Crontab在Linux系统中实现任务的并行执行在Linux系统中,任务的并行执行是提高系统效率和性能的重要手段之一。本文将介绍如何使用Systemd和Crontab两个工具,在Linux系统中实现任务的并行执行,并提供具体的代码示例。一、Systemd介绍Systemd是一个用于管理Linux系统启动流程和服务管理的工具。通过配置

linux注释crontab文件及crontab执行sh的坑怎么解决linux注释crontab文件及crontab执行sh的坑怎么解决May 15, 2023 pm 09:58 PM

linux注释crontab文件及crontab执行sh的坑原来,在Linux下写了很多crontab,来定时执行某些任务,现在有以下需求:需求:是要注释某些crontab任务,方法:只要在所要取消的crontab任务前,加'#'即可。e.g.54**sunecho"runat5after4everysunday"注释:#54**sunecho"runat5after4everysunday"就这么简单。遇坑1看下面例子最近

linux crontab 错误日志怎么看linux crontab 错误日志怎么看Mar 07, 2023 am 09:29 AM

linux查看crontab错误日志的方法:1、查看文件目录“/var/log/cron”;2、通过“tail -f /var/log/cron”命令实现实时文件尾部查看;3、通过“vim /var/log/cron”命令实现通过高级文本查看器查看即可。

如何使用Systemd和Crontab在Linux系统中自动重启应用程序如何使用Systemd和Crontab在Linux系统中自动重启应用程序Sep 28, 2023 pm 03:35 PM

如何使用Systemd和Crontab在Linux系统中自动重启应用程序在Linux系统中,Systemd和Crontab是两个非常重要的工具。Systemd是一个系统和服务管理器,而Crontab则是一个用于在指定时间自动执行任务的工具。本文将以一个具体的例子,介绍如何使用Systemd和Crontab在Linux系统中自动重启应用程序。假设我们有一个No

如何在Linux系统中使用Systemd和Crontab实现系统自启动如何在Linux系统中使用Systemd和Crontab实现系统自启动Sep 26, 2023 am 11:57 AM

如何在Linux系统中使用Systemd和Crontab实现系统自启动引言:在Linux系统中,我们经常需要将一些常用的服务或脚本设置为系统自启动,以便系统重启后能够自动运行。在本文中,将介绍如何使用Systemd和Crontab这两个工具来实现系统自启动,并给出具体的代码示例。一、Systemd的使用Systemd是Linux操作系统中常用的系统和服务管理

如何利用Systemd和Crontab在Linux系统中设置定时任务的优先级如何利用Systemd和Crontab在Linux系统中设置定时任务的优先级Sep 27, 2023 am 08:25 AM

如何利用Systemd和Crontab在Linux系统中设置定时任务的优先级,需要具体代码示例在Linux系统中,我们经常需要设置定时任务来执行一些重复性的操作,例如定时备份文件、定期清理日志等。然而,不同的任务可能具有不同的优先级,有些任务需要更高的优先级来确保其准时执行,而有些任务则可以稍后执行。本文将介绍如何利用Systemd和Crontab来设置定时

Linux Crontab错误日志排查技巧分享Linux Crontab错误日志排查技巧分享Mar 18, 2024 am 09:21 AM

LinuxCrontab错误日志排查技巧分享在Linux系统中,Crontab是一种非常常用的定时任务管理工具,可以帮助用户定期执行特定的任务。然而,有时候在使用Crontab时会遇到一些错误,需要及时排查和解决。本文将分享一些排查Crontab错误日志的技巧,以及如何通过具体代码示例来定位和解决问题。查看Crontab日志首先,我们可以查看Crontab

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool