Simple backup policy for small and medium-sized sites is based on drupal's small and medium-sized websites. We can use the backup_migrate module, which provides the regular backup function, backup time, number of backups retained, and so on, after the configuration is complete, execute cron regularly to make the backup successful. For a typical Drupal website, we only need to use svn. on the server side, we
Simple backup policy for small and medium-sized sites is based on drupal's small and medium-sized websites. We can use the backup_migrate module, which provides the regular backup function, backup time, number of backups retained, and so on, after the configuration is complete, execute cron regularly to make the backup successful. For a typical Drupal website, we only need to use svn. on the server side, we
Simple backup policy for small and medium sites
For small and medium-sized websites based on drupal, we can use the backup_migrate module, which provides the regular backup function, backup time, number of backups retained, and so on, regular cron execution can successfully back up data. For a typical Drupal website, we only need to use svn. on the server side, we can submit the backed up data to svn to achieve the goal of backup. Because the Drupal backup module can set the number of copies retained for backup, it does not cause too many backup files, resulting in a large svn.
The following is a simple backup script, which is placed in the root directory of the site and then added to crontab for daily execution.
#!/bin/bash date #start dateDRUSH_PHP=/bin/php #php pathexport DRUSH_PHP drush cronsvn st sites/default/files/backup_migrate/scheduled/ | grep '^!' | awk '{print $2}' | xargs svn delete --forcesvn add sites/default/files/backup_migrate/scheduled/*svn ci sites/default/files/backup_migrate/scheduled/ -m 'add backup files'date #end date
Crontab settings are as follows:
0 0 * cd/www/web/html/& bash cron. sh> cron. log 2> & 1
MySQL backup policies for large sites
If it is a site with a slightly larger database, temporary svn Backup will be slightly thin. In this case, you need to use the MySQL backup policy. Generally, we need to back up and compress the entire database, it is then regularly transferred to the backup database or placed on another ECs instance. A simple PHP sample code is provided here.
#!/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 settings
0 1 ***/home/robbin/bin/mysql_backup.php
In addition, we need to regularly transmit the backup data to other servers to avoid data loss caused by server crashes. The website can be backed up in a timely manner. Here we only share a little bit of information about the operations. We have a better backup policy. You are welcome to share it.