MySQL 定时备份操作
1、创建保存备份文件的路径/mysqldata #mkdir /bak/mysqlbak 2、创建/usr/sbin/bakmysql文件 #vi /usr/sbin/bakmysql.sh
1、创建保存备份文件的路径/mysqldata
#mkdir /bak/mysqlbak
2、创建/usr/sbin/bakmysql文件
#vi /usr/sbin/bakmysql.sh
3、写入脚本如下脚本
注意,如果是你的mysql密码是带有特殊字符的,比如!@# ,那么需要在 -p参数后面加上‘’,把密码放在‘’中,'123!@#'
#!/bin/bash
#Name:bakmysql.sh
#This is a ShellScript For Auto DB Backup and Delete old Backup
backupdir=/bak/mysqlbak
time=` date +%Y%m%d%H `
mysqldump --opt -h192.168.1.1 -uroot -p123456 dbname | gzip > $backupdir/mo$time.sql.gz
#
find $backupdir -name "mo*.sql.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1
脚本解析:
backupdir 数据库备份路径
time时间点
mysqldump :mysql备份工具,--opt -h 远程执行备份操作,,
dbname:数据库名称,
gzip:压缩成gzip格式的。
最后一个行是保证5最新个备份文件
4、定时任务
修改/etc/crontab
#vi /etc/crontab
在下面添加
01 3 * * * root /usr/sbin/bakmysql
表示每天3点钟执行备份
5、重新启动crond
# /etc/rc.d/init.d/crond restart (RedHat)
#/etc/init.d/cron restart (Ubuntu)
完成。
手工恢复:
先解压gz文件
gunzip xxx.gz
mysql -u root -p --default-character-set=utf8
use dbname
source /root/xx.sql
搞定
so esay ,那里不会点那里。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

How to use MySQL data backup and recovery tools to achieve disaster recovery. Data backup and recovery are a very important part of the database management process. Backing up your data protects your database from accidental corruption, hardware failure, or other catastrophic events. As a popular relational database management system, MySQL provides some powerful tools to achieve data backup and recovery. This article will introduce how to use MySQL's data backup and recovery tools to achieve disaster recovery. MySQL data backup tool-mysql

In the MySQL database, each InnoDB table corresponds to an .ibd file, which stores the table's data and indexes. Therefore, for the management and maintenance of MySQL database, the management of ibd files is also particularly important. This article will introduce how to effectively manage and maintain ibd files in a MySQL database and provide specific code examples. 1. Check and optimize table space First, we can check the disk space usage of the table using the following SQL statement: SELECTTAB

MySql is a commonly used relational database management system that is widely used in various business and application scenarios. For MySQL backup issues, the selection and execution method of the backup plan are crucial. In this article, we will introduce various backup options and how to create and restore MySQL backups efficiently. 1. Selection of backup plan In the process of selecting a MySQL backup plan, you should choose a backup plan that suits you based on the business scenario and actual situation. Cold backup The so-called cold backup is to complete the MySQL database.

There is no absolutely optimal MySQL database backup and recovery solution, and it needs to be selected based on the amount of data, business importance, RTO and RPO. 1. Logical backup (mysqldump) is simple and easy to use, suitable for small databases, but slow and huge files; 2. Physical backup (xtrabackup) is fast, suitable for large databases, but is more complicated to use. The backup strategy needs to consider the backup frequency (RPO decision), backup method (data quantity and time requirement decision) and storage location (off-site storage is more secure), and regularly test the backup and recovery process to avoid backup file corruption, permission problems, insufficient storage space, network interruption and untested issues, and ensure data security.

MySQL is one of the most widely used relational database management systems currently. Its efficiency and reliability make it the first choice for many enterprises and developers. But for various reasons, we need to back up the MySQL database. Backing up a MySQL database is not an easy task because once the backup fails, important data may be lost. Therefore, in order to ensure data integrity and recoverability, some measures must be taken to achieve efficient MySQL database backup and recovery. This article will introduce how to achieve

MySQL is a popular relational database that is widely used in various fields. However, like other applications, MySQL has risks such as data corruption, crashes, and malicious attacks. Therefore, backing up your data is crucial. Backups can provide security and some form of "undo" functionality to data, reducing or even eliminating instability and risk. The most common backup types are full backup and incremental backup. However, if you need frequent, real-time backups, rolling backups are a better approach. A rolling backup is when an acceptable

MySQL is currently one of the most popular relational database management systems and is widely used in enterprise-level applications. Whether you are a developer or a data administrator, you need to understand the basic knowledge of MySQL backup and recovery. Backup and recovery not only help enterprises protect data, but also enable systems to respond quickly to adverse situations and restore them to normal operating conditions as much as possible. This article will detail the steps for MySQL backup and recovery and provide some best practices to help readers go further in protecting their MySQL databases.

Analysis of MySQL database backup and recovery performance tuning project experience In daily operation and maintenance, MySQL database backup and recovery work is indispensable. However, in the face of multi-terabyte or even petabyte-level data scale, the time and resource consumption required for backup and recovery often become key factors restricting database performance. This article will share some practical experiences and techniques through a practical case of backup and recovery performance tuning for a large Internet enterprise. 1. Selection of backup solutions. Based on different business needs and data scale, the selection of backup solutions should also be considered.
