MYSQL数据库自动本地/异地双备份/MYSQL增量备份
构建高安全电子商务网站之(网站文件及数据库自动本地/异地双备份)架构图
继续介绍Linux服务器文件备份,数据库备份,数据安全存储相关的电子商务系统架构。针对安全性有多种多样的解决方案,其中数据备份是重中之重的首要工作。
电 子商务网站更加注重考虑数据安全,数据备份方案,包括本地备份、异地备份架构。其中Linux服务器的备份方案非常多,本文介绍一个大众化适用的解决方 案,通过编写Shell脚本来完成自动备份。本架构包括备份网站文件、数据库,自动本地备份并FTP上传备份脚本,完成相应本地备份、异地备份,实现双层 备份解决方案。
本文要点:
1.MYSQL数据库自动本地/异地双备份/MYSQL数据库增量备份。
2.编写Shell脚本来完成自动MYSQL备份、MYSQL数据库增量备份。
3.同时进行自动本地/异地双备份,FTP上传备份。
4.Linux服务器的备份解决方案。
5.Shell脚本包括备份网站文件,网站程序文件、数据文件,MYSQL数据库。
6.定期定时自动完成备份。定期删除旧备份,这里是自动删除30天前备份,复用利用备份空间。
目录:
一、准备工作
二、网站运维异地备份方案及故障应急备用镜像站架构图
三、网站MYSQL数据库自动本地/异地双备份/MYSQL数据库增量备份Shell脚本,完整的实例;备份脚本进行详细解说,注释。
在 运营中的电子商务网站,建站之初就一直在重申一定要备份好自己的数据,因为太多的不确定性可能会造成数据库丢失,而且大部分基础服务商也不可能提供每天备 份数据。原来本BLOG提供过一个备份方法,介绍了Shell脚本MYSQL数据库自动备份,没有介绍MYSQL数据库增量备份。今天分享一个自己的备份 脚本。
参考之前的文章 http://jimmyli.blog.51cto.com/3190309/691069 《构建高安全电子商务网站之(网站文件及数据库自动本地/异地双备份)[连载之电子商务系统架构]》
一、准备工作:
Linux服务器安装好lftp,另外需要提前在Linux服务器上创建/home/backup/ 备份目录建立。并且保证FTP能正常使用账户密码登陆上次文件。既是保证FTP服务正常提供服务。
二、网站运维异地备份方案及故障应急备用镜像站架构图
三、网站MYSQL数据库自动本地/异地双备份/MYSQL数据库增量备份Shell脚本
脚本二:
MYSQL数据库增量备份Shell脚本
如果数据库数据量比较大,可以一天全备一次, 再每隔一小时增量备份一次;
建立增量备份目录
增量备份的文件放在/backup/mysql/daily目录下。
增量备份的数据量比较小,但是要在完整备份的基础上操作。
增量备份使用bin log,脚本如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
#!/bin/sh # mysql data backup script
#Author: Jimmy Li #Website: http://jimmyli.blog.51cto.com/ # mysql binlog backup script /usr/bin/mysqladmin flush-logs DATADIR=/var/lib/mysql BAKDIR=/backup/mysql/daily ###如果mysql bin log你做了特殊设置,请修改此处或者修改应用此变量的行:缺省取机器名,mysql缺省也是取机器名 HOSTNAME=`uname -n` cd $DATADIR
## COUNTER number COUNTER=0
do COUNTER=`expr $COUNTER + 1 ` done NextNum=0
do base=`basename $file` NextNum=`expr $NextNum + 1` if [ $NextNum -eq $COUNTER ] then
else dest=$BAKDIR/$base if(test -e $dest) then
else
cp $base $BAKDIR fi fi done
|
脚本解析说明:
增量备份脚本是备份前flush-logs,mysql会自动把内存中的日志放到文件里,然后生成一个新的日志文件,所以我们只需要备份前面的几个即可,也就是不备份最后一个.
因为从上次备份到本次备份也可能会有多个日志文件生成,所以要检测文件,如果已经备份过,就不用备份了.
温馨提示、增量备份:
每天中午03点和晚上03点做一次全备,每隔一小时备份binlog,也就是增量备份,具体操作如下:
Linux下开启binlog
将脚本放到/root/ 下面,按上面的注释修改脚本中的参数,使用vim编辑器并保存。
执行:chmod +x /root/backup.sh 为脚本添加执行权限。
执行:crontab -e 添加定时执行。
在crontab中加入:0 3 * * * /root/backup.sh
凌晨3点自动执行/root/bakcup.sh 脚本,备份Linux服务器上的数据并上传到预先设定好的异地FTP上。
选择在凌晨3进行备份,是因为这个时间段网站的访问量是最低。也就是说在很少人访问的情况下做备份操作。
12345678910 |
/etc/my.cnf中的mysqld部分加入: [mysqld] log-bin=../logs/mysql-bin
windows下开启binlog %mysql%/my.ini中的mysqld部分加入: [mysqld] log-bin =../logs/mysql-bin
|
脚本一:
网站及数据库自动本地备份并FTP上传备份Shell脚本,完整的实例:
123456789101112131415161718192021222324252627282930 |
#!/bin/bash
#Author: Jimmy Li #Website: http://jimmyli.blog.51cto.com/
Backup_Dir1=/data/wwwroot/jimmyli.jimmyli.jimmyli.blog.51cto.com MYSQL_UserName=root MYSQL_PassWord=你的mysql数据库root密码 Backup_Database_Name1=jimmyli.jimmyli.jimmyli.blog.51cto.com FTP_HostName=jimmyli.jimmyli.jimmyli.blog.51cto.com FTP_UserName=jimmyli.jimmyli.jimmyli.blog.51cto.com FTP_PassWord=jimmyli.jimmyli.jimmyli.blog.51cto.com FTP_BackupDir=jimmyli.jimmyli.jimmyli.blog.51cto.com
rm $OldWWWBackup rm $OldDBBackup cd /home/backup/ lftp $FTP_HostName -u $FTP_UserName,$FTP_PassWord <code>cd $FTP_BackupDir mrm $OldWWWBackup mrm $OldDBBackup mput $TodayWWWBackup mput $TodayDBBackup bye EOF
|
备份脚本进行详细解说,注释参考 http://jimmyli.blog.51cto.com/3190309/691069 《构建高安全电子商务网站之(网站文件及数据库自动本地/异地双备份)[连载之电子商务系统架构]》
========================================================================
网站运维异地备份方案及故障应急备用镜像站
定期检查异地备份故障应急时,启用应急Web服务
连接:http://jimmyli.blog.51cto.com/3190309/584992 网站运维异地备份方案及故障应急备用镜像站
本文出自 “Jimmy Li我站在巨人肩膀上” 博客,请务必保留此出处http://jimmyli.blog.51cto.com/3190309/888630

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





Win11 is the latest operating system launched by Microsoft. Compared with previous versions, Win11 has greatly improved the interface design and user experience. However, some users reported that they encountered the problem of being unable to install the Chinese language pack after installing Win11, which caused trouble for them to use Chinese in the system. This article will provide some solutions to the problem that Win11 cannot install the Chinese language pack to help users use Chinese smoothly. First, we need to understand why the Chinese language pack cannot be installed. Generally speaking, Win11

Reasons and solutions for scipy library installation failure, specific code examples are required When performing scientific calculations in Python, scipy is a very commonly used library, which provides many functions for numerical calculations, optimization, statistics, and signal processing. However, when installing the scipy library, sometimes you encounter some problems, causing the installation to fail. This article will explore the main reasons why scipy library installation fails and provide corresponding solutions. Installation of dependent packages failed. The scipy library depends on some other Python libraries, such as nu.

Title: An effective solution to solve the problem of garbled characters caused by Oracle character set modification. In Oracle database, when the character set is modified, the problem of garbled characters often occurs due to the presence of incompatible characters in the data. In order to solve this problem, we need to adopt some effective solutions. This article will introduce some specific solutions and code examples to solve the problem of garbled characters caused by Oracle character set modification. 1. Export data and reset the character set. First, we can export the data in the database by using the expdp command.

Common problems and solutions for OracleNVL function Oracle database is a widely used relational database system, and it is often necessary to deal with null values during data processing. In order to deal with the problems caused by null values, Oracle provides the NVL function to handle null values. This article will introduce common problems and solutions of NVL functions, and provide specific code examples. Question 1: Improper usage of NVL function. The basic syntax of NVL function is: NVL(expr1,default_value).

Common challenges faced by machine learning algorithms in C++ include memory management, multi-threading, performance optimization, and maintainability. Solutions include using smart pointers, modern threading libraries, SIMD instructions and third-party libraries, as well as following coding style guidelines and using automation tools. Practical cases show how to use the Eigen library to implement linear regression algorithms, effectively manage memory and use high-performance matrix operations.

Common reasons and solutions for Chinese garbled characters in MySQL installation MySQL is a commonly used relational database management system, but you may encounter the problem of Chinese garbled characters during use, which brings trouble to developers and system administrators. The problem of Chinese garbled characters is mainly caused by incorrect character set settings, inconsistent character sets between the database server and the client, etc. This article will introduce in detail the common causes and solutions of Chinese garbled characters in MySQL installation to help everyone better solve this problem. 1. Common reasons: character set setting

PyCharm is a powerful Python integrated development environment that is widely loved by developers. However, sometimes we may encounter key invalidation problems when using PyCharm, resulting in the inability to use the software normally. This article will reveal the solution to PyCharm key failure and provide specific code examples to help readers quickly solve this problem. Before we start solving the problem, we first need to understand why the key is invalid. PyCharm key failure is usually due to network problems or the software itself

Analysis of Java framework security vulnerabilities shows that XSS, SQL injection and SSRF are common vulnerabilities. Solutions include: using security framework versions, input validation, output encoding, preventing SQL injection, using CSRF protection, disabling unnecessary features, setting security headers. In actual cases, the ApacheStruts2OGNL injection vulnerability can be solved by updating the framework version and using the OGNL expression checking tool.
