linux下mysql自动备份数据库与自动删除临时文件
mysql自动备份数据库与自动删除临时文件,有需要的朋友可以参考下
一、每日23:00自动删除临时文件
首先查看一下crontab的任务列表:
crontab -l
然后新建:
crontab -e
添加一行:
00 03 * * * rm -rf /www/cmstest/my120/public/scripts/jpgraph/*
保存退出。
重启服务: /etc/rc.d/init.d/crond restart
二、每日24:00自动备份数据库
利用系统crontab来定时执行备份文件,按日期对备份结果进行保存,达到备份的目的。
1、创建保存备份文件的路径/mysqldata
#mkdir /mysqldata
2、创建/usr/sbin/bakmysql文件
查找数据库库文件的路径:
一般都是:/var/lib/mysql,或者,/usr/local/mysql/var
查找方法:
1、/usr/local/mysql/bin/mysql -u root -p 进入数据库
2、输入:show databases;
3、这是可以查看到所有的数据库,然后
4、find / -name db(你想查找的数据库名)
之后:#vi /usr/sbin/bakmysql
输入
代码如下:
rq=` date +%Y%m%d `
tar zcvf /mysqldata/mysql$rq.tar.gz /var/lib/mysql
3、修改文件属性,使其可执行
# chmod +x /usr/sbin/bakmysql
新建任务:
首先查看一下crontab的任务列表:
crontab -l
然后新建:
crontab -e
添加一行
00 04 * * * /usr/sbin/bakmysql
表示每天24点钟执行备份
4、重新启动crond
# /etc/rc.d/init.d/crond restart
此后每天就可以在/mysqldata中看到类似下的文件了:mysql20040619.tar.gz。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Some Windows 10 users have found that the system's built-in automatic backup function is activated during use. Although this function helps ensure data security, some users may not feel the need to continue enabling it due to storage space considerations or other reasons. This function. Therefore, if you want to turn off the automatic backup function in Windows 10 system, the correct operation steps are particularly important. Next, this article will introduce in detail how to turn off the automatic backup function of the Win10 system for the reference implementation of users who have this need. Close method 1. Use the "win+i" shortcut key to quickly open the "Settings" page. After entering the new page, you need to click the "Update and Security" option. 2. In the new interface that opens, click in the left column

Are you also using Quark Network Disk software? But do you know how to automatically back up Quark Network Disk? The editor below will bring you the method of automatic backup of Quark Network Disk, let us take a look below. Open Quark Network Disk on the desktop. Click on my avatar to enter the main interface. Click the Quark Network Disk automatic backup option to turn it on.

With the popularity of Internet applications, database backup is particularly important for website operation and maintenance and data security. Manual backup can certainly provide certain protection, but for websites with large amounts of data, manual backup is obviously cumbersome and time-consuming. At this time, the automatic backup method has become an indispensable choice. One of the more popular and easy-to-understand automatic backup methods is to use PHP scripts to automatically backup the MySQL database. This article will introduce how to use PHP to implement automatic backup of MySQL database. 1. Backup My

1. Press the [Win+R] keys to open the run; as shown in the figure: 2. Enter cmd in the following window to open the command line window; as shown in the figure: 3. Enter the command robocopy in the command line window to view it. Corresponding parameter description; as shown in the figure: 4. For example, to automatically back up the demo folder under E drive to the demo folder under H drive every 10 minutes, use the following command: robocopyE:demoD:demo/R:0/ W:0/MOT:10; As shown in the figure: 5. The parameter R above represents the number of retries after the backup fails, W is the retry interval, and MOT represents the time interval of automatic backup; as shown in the figure: 6 . After the automatic backup is completed, you can see the automatically backed up folder under the D drive.

With the wide application of Redis database in Internet applications, more and more enterprises and developers have begun to pay attention to the backup and protection of Redis database. Automatic backup is an effective means to ensure the security of Redis. This article will introduce how to use PHP to implement automatic backup of the Redis database. 1. Redis database backup Redis is an open source key-value database. It not only supports basic data types, but also supports complex data structures, such as lists, hash tables, and sets. Redis backup can be

1. Enter Xiaomi WiFi and click on the toolbox in the lower right corner. 2. Find the routing settings. 3. Enter the router configuration backup. 4. Click to turn on automatic backup of router settings.

In the process of using Baidu Netdisk, we can set up a function that allows automatic backup of photos. The following is an introduction to the operation method. Interested friends come with me to take a look. After opening the Baidu Netdisk application on your mobile phone, enter the main interface, and then click the "My" button in the lower right corner to enter the personal center page. Next, find the "Settings and Services" option at the bottom of the page, click to enter and select the "Settings" function to open the settings page. 2. There is an "Automatic Backup Setting" on the settings page, click on it to enter. 3. Next, click the "Album Backup" item on the entered page to enter. 4. After coming to the new page, you will see a switch button behind "Automatically backup photos". Click the circular slider on it to set it.

With the continuous development of Internet technology, the importance of databases has become increasingly prominent. The database is an important carrier for storing data. If the database fails, problems such as data loss and data inconsistency will cause huge losses to the enterprise. In order to ensure data security and integrity, a backup solution must be adopted. This article will introduce how to use PHP to realize automatic backup of MongoDB database to help enterprises improve data security. 1. Introduction to MongoDB backup MongoDB is a brand new non-relational database that can store sea
