Home Database Mysql Tutorial MySql数据库本地服务器备份策略

MySql数据库本地服务器备份策略

Jun 07, 2016 pm 05:54 PM
mysql database

说明:我这里要把MySql数据库存放目录/var/lib/mysql下面的所有文件备份到/home/mysql_data里面 并且保存为mysql_data20121220.tar.gz的压缩文件(20121220是指备份执行时当天的日期) 然后只保留最近7天的备份 1、创建保存备份文件的路径:/home/mysql_data

说明:我这里要把MySql存放目录/var/lib/mysql下面的所有文件备份到/home/mysql_data里面
并且保存为mysql_data20121220.tar.gz的压缩文件(20121220是指备份执行时当天的日期)
然后只保留最近7天的备份

1、创建保存备份文件的路径:/home/mysql_data
cd /home
mkdir mysql_data
2、创建备份脚本文件:/home/mysql_data/mysql_databak.sh

cd /home
cd mysql_data
touch mysql_databak.sh
vim mysql_databak.sh
输入以下内容:
##################################################################################
#!/bin/sh
/etc/init.d/mysqld stop #执行备份前先停止MySql,防止有数据正在写入,备份出错
date=` date +%Y%m%d ` #获取当前日期
DAYS=7 #DAYS=7代表删除7天前的备份,即只保留最近7天的备份
BK_DR=/home/mysql_data #备份文件存放路径
DB_DR=/var/lib/mysql #数据库路径
LINUX_USER=root #系统用户名
tar zcvf $BK_DR/mysql_data$date.tar.gz $DB_DR #备份数据
/etc/init.d/mysqld start #备份完成后,启动MySql
chown -R $LINUX_USER:$LINUX_USER $BK_DR #更改备份数据库文件的所有者
find $BK_DR -name "mysql_data*" -type f -mtime +$DAYS -exec rm {} \; #删除7天前的备份文件
##################################################################################

3、修改文件属性,使其可执行

chmod +x /home/mysql_data/mysql_databak.sh

4、修改/etc/crontab
vi /etc/crontab
在下面添加

35 13 * * * root /home/mysql_data/mysql_databak.sh
表示每天13点35钟执行备份

5、重新启动crond使设置生效
/etc/rc.d/init.d/crond restart
chkconfig crond on #设为开机启动
service crond start #启动

每天你在/home/mysql_data目录下面可以看到类似mysql_data20121220.tar.gz这样的压缩文件
如果需要恢复文件的时候,只需要把这个文件解压即可
解压缩tar -zxvf mysql_data20121220.tar.gz

Statement of this Website
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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Apr 08, 2025 pm 07:12 PM

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

The primary key of mysql can be null The primary key of mysql can be null Apr 08, 2025 pm 03:03 PM

The MySQL primary key cannot be empty because the primary key is a key attribute that uniquely identifies each row in the database. If the primary key can be empty, the record cannot be uniquely identifies, which will lead to data confusion. When using self-incremental integer columns or UUIDs as primary keys, you should consider factors such as efficiency and space occupancy and choose an appropriate solution.

Can mysql run on android Can mysql run on android Apr 08, 2025 pm 05:03 PM

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

Can mysql return json Can mysql return json Apr 08, 2025 pm 03:09 PM

MySQL can return JSON data. The JSON_EXTRACT function extracts field values. For complex queries, you can consider using the WHERE clause to filter JSON data, but pay attention to its performance impact. MySQL's support for JSON is constantly increasing, and it is recommended to pay attention to the latest version and features.

Can mysql handle multiple connections Can mysql handle multiple connections Apr 08, 2025 pm 03:51 PM

MySQL can handle multiple concurrent connections and use multi-threading/multi-processing to assign independent execution environments to each client request to ensure that they are not disturbed. However, the number of concurrent connections is affected by system resources, MySQL configuration, query performance, storage engine and network environment. Optimization requires consideration of many factors such as code level (writing efficient SQL), configuration level (adjusting max_connections), hardware level (improving server configuration).

mysql whether to change table lock table mysql whether to change table lock table Apr 08, 2025 pm 05:06 PM

When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

See all articles