Home Database Mysql Tutorial Linux下简单的MySQL/Web备份小实例

Linux下简单的MySQL/Web备份小实例

Jun 07, 2016 pm 05:06 PM
mysql backup

这个是菜鸟级的运维的MySQL的备份小脚本,在这里写出来一是为了做笔记,二是认识一下两个小工具mysqldump/pdumpfs

这个是菜鸟级的运维的MySQL的备份小脚本,在这里写出来一是为了做笔记,二是认识一下两个小工具mysqldump/pdumpfs

第一部分是mysql数据的备份

[root@localhost ~]# mkdir -p /usr2/backup/mysql

[root@localhost ~]# vi mysqldump.sh
#!/bin/bash
#author XXX  time 2011-10-17
#the backup of localhost mysql data
X=`date +%Y%m%d`
M=/usr/local/mysql/bin
B=/usr2/backup/mysql

$M/mysqldump -uroot --all-databases > $B/$X.sql  //本机的mysql为设置登录密码,如果设置密码需要改写这句话($M/mysqldump -uroot -ppassword --all-databases > $B/$X.sql)
tar zcvf $B/$X.tar.gz $B/$X.sql
rm -rf $B/$X.sql
[root@localhost ~]# chmod a+x mysqldump.sh
[root@localhost ~]# ./mysqldump.sh
tar: Removing leading `/' from member names
/usr2/backup/mysql/20111015.sql

以上这个脚本可以加入cron的计划任务中,在定时的时刻执行备份的动作!

[root@localhost ~]# echo " * * * * * root path/XX.sh & >/dev/null" >> /etc/crontab
至于灾难恢复的语句可以这么写

[root@localhost ~]# /usr/local/mysql/bin/mysqldump -uroot -ppassword 每周的备份数据量是很大的,下边的那句话可以写入cron.weekly来清除重叠的数据

[root@localhost ~]# find /usr2/backup/mysql -mtime +6 -exec rm {}\;

第二部分是web数据的备份

这里采用一个新发现的小工具pdumpfs

[root@localhost ~]# yum -y install ruby (安装需要的套件包)

[root@localhost ~]# wget
[root@localhost ~]# rpm -ivh pdumpfs-1.3-1.rh9.rf.i386.rpm

[root@localhost web]# mkdir /usr2/backup/web

[root@localhost ~]# vim web.sh
#!/bin/bash
#author XXX time 2011-10-17
pdumpfs /var/www /usr2/backup/web >/usr2/backup/web/message.log 2>/usr2/backup/web/error.log
[root@localhost ~]# chmod a+x web.sh
同时可以把这个小脚本放入cron的计划任务中定期的执行

[root@localhost ~]# echo " * * * * * root path/XX.sh & >/dev/null" >> /etc/crontab
[root@localhost ~]# ls /usr2/backup/web/ (哲就是备份的数据部分)
2011  error.log  latest  message.log
第三部分是ssh的异地的无密码复制的设置

两台linux主机,一台ip:(也就是服务器本机)另一台是(作为远程备份主机)

首先在远程备份主机上的操作

[root@localhost ~]# ssh-keygen (生成公匙)

[root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa (给服务器送去,这步要输入192的密码)

[root@localhost ~]# scp :/usr2/backup/mysql/20111015.tar.gz .(这里显示的是可以不使用密码可以直接的从服务器上拷贝东西了,,也就是复制的过程。把这里换成脚本就能实现很多的操作)

总结:备份的主要方式有,完整备份,增量备份,差分备份、还有本地和异地备份之分!这里只是一个文件备份的小实例,期待进一步的学习!

linux

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

Multiple backup solutions for MySql: How to efficiently create and restore MySQL backups Multiple backup solutions for MySql: How to efficiently create and restore MySQL backups Jun 15, 2023 pm 03:28 PM

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.

MySQL rolling backup techniques for data MySQL rolling backup techniques for data Jun 15, 2023 pm 07:47 PM

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 database backup: How to achieve efficient MySQL database backup and recovery MySql database backup: How to achieve efficient MySQL database backup and recovery Jun 15, 2023 pm 11:37 PM

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

How to use MySQL data backup and recovery tools for disaster recovery How to use MySQL data backup and recovery tools for disaster recovery Aug 02, 2023 am 09:06 AM

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

How to effectively manage and maintain ibd files in MySQL database How to effectively manage and maintain ibd files in MySQL database Mar 16, 2024 am 11:21 AM

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

Analysis of project experience on MySQL database backup and recovery performance tuning Analysis of project experience on MySQL database backup and recovery performance tuning Nov 04, 2023 am 09:46 AM

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.

Project experience summary of MySQL database backup and disaster recovery solutions Project experience summary of MySQL database backup and disaster recovery solutions Nov 02, 2023 pm 03:54 PM

Project experience summary of MySQL database backup and disaster recovery plan In the project, the database backup and disaster recovery plan is a very important work content. As a commonly used relational database management system, MySQL’s formulation and implementation of backup and disaster recovery plans are key to ensuring data security and availability. I have accumulated some experience in past project implementations and summarized them as follows. 1. Formulation of backup strategy Developing a reasonable backup strategy is crucial to the security of the database. Generally speaking, backup strategies need to consider the following:

A comprehensive guide to MySQL backup and recovery A comprehensive guide to MySQL backup and recovery Jun 15, 2023 am 09:48 AM

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.

See all articles