中小站点简单备份策略 基于drupal的中小行网站,我们可以使用backup_migrate模块,该模块提供了定期备份的功能,备份的时间、保留多少个备份等等设置,设置好之后,定期执行cron即可备份成功。 一般的Drupal小站,我们只需使用svn即可,在服务器端,我们把备
中小站点简单备份策略
基于drupal的中小行网站,我们可以使用backup_migrate模块,该模块提供了定期备份的功能,备份的时间、保留多少个备份等等设置,设置好之后,定期执行cron即可备份成功。 一般的Drupal小站,我们只需使用svn即可,在服务器端,我们把备份好的数据提交到svn,就可以达到备份的目的。由于Drupal的备份模块可以设置备份保留的文件份数,因此不会造成太多的备份文件,从而导致svn很大。
下面是一个简单的备份脚本,放置到站点根目录,然后加到crontab每天执行即可。
#!/bin/bash date #start date DRUSH_PHP=/bin/php #php path export DRUSH_PHP drush cron svn st sites/default/files/backup_migrate/scheduled/ | grep '^!' | awk '{print $2}' | xargs svn delete --force svn add sites/default/files/backup_migrate/scheduled/* svn ci sites/default/files/backup_migrate/scheduled/ -m 'add backup files' date #end date
crontab的设置如下
0 0 * * * cd /www/web/html/ && bash cron.sh > cron.log 2>&1
大型站点MySQL备份策略
如果是数据库稍大的站点,使用svn临时备份就略显单薄,这时需要使用MySQL备份策略,一般情况下我们需要把整个数据库都备份压缩,然后定期转移到备份数据库或者放到其他的云服务器,这里给出一个简单的PHP示例代码。
#!/usr/bin/php -q <?php $to = "gaoxinzhao@gmail.com"; $hostname = exec('/bin/hostname'); $mycnf = "/home/robbin/.my.cnf"; $ignore = array('information_schema', 'test', 'mysql', 'wdcpdb'); function trimw($str) { $str = str_replace(array("n", "r", "t", " ", "o", "xOB"), '', $str); return $str; } if (!file_exists($mycnf)) { mail($to, "No .my.cnf exists on $hostname", "MySQL cannot dump because .my.cnf is missing on $hostname .") ; exit("cant get user creds"); } $myconf = file_get_contents($mycnf) or die( "Failed to open bmesh_admin's .my.cnf" ); preg_match( "/buser(.*)/", $myconf, $matches ) or die( mail($to, "No username in .my.cnf on $hostname", "MySQL cannot dump on $hostname")); $usr = (explode('=', $matches[0])); $user = trimw($usr[1]); preg_match( "/bpassword(.*)/", $myconf, $matches ) or die( mail($to, "No password in .my.cnf on $hostname", "MySQL cannot dump on $hostname")); $pass = (explode('=', $matches[0])); $password = trimw($pass[1]); mysql_connect("localhost",$user,$password) or die ("could not connect: " . mysql_error()); mysql_select_db("mysql"); $result = mysql_query("show databases"); $bpath = "/home/robbin/backup/mysql"; $btime = date("Y-m-d H:i:s"); $bstamp = strtotime($btime); $byear = date("Y", $bstamp); $bmonth = date("m", $bstamp); $bday = date("d", $bstamp); $btod = date("H-i-s", $bstamp); while ($res = mysql_fetch_array($result)) { $myDb = $res["Database"]; if (in_array($myDb, $ignore)) continue; $mdir = "$bpath/$byear/$bmonth/$bday/$btod/$myDb"; $out = `mkdir -p $mdir`; $myFile = $myDb . ".sql"; $bldCmd = "cd $mdir ; "; $bldCmd .= "mysqldump -u$user -p$password --single-transaction --add-drop-table -R -c -Q $myDb > $myFile ;"; //$bldCmd .= "chmod 644 $myFile ; "; //$bldCmd .= "chown root:root $myFile ; "; $bldCmd .= "gzip -9 $myFile"; print "Backing up $myDbn"; print "Securing $myDbn"; $out = `$bldCmd`; } $out = `chmod 700 $bpath/$byear`; print "$outn"; print "Backups are in $bpathn";
crontab的设置
0 1 * * * /home/robbin/bin/mysql_backup.php
此外我们需要把备份的数据还要定期传送到其他服务器上,才会避免服务器崩溃而引发数据丢失。备份及时网站才有保证,这里仅仅只是笔者的一点点操作分享,大家有更好的备份策略,欢迎共享。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools