仓促执行数据库备份/转储吗?


Answers:


7

不,不是。它仅在备份当前模块目录之前对其进行备份。

要创建一个SQL转储,使用

drush sql-dump > filename.sql.

但是请记住将文件移到您的webroot之外。


我想提醒人们在您的网站根目录之外进行转储;因此黑客将远离。
chrisjlee 2011年

此“接受的”答案不正确。Drush实际上确实提供了数据库的转储:“ drush sql-dump” drushcommands.com/drush-7x/sql/sql-dump
sea26.2

嗯 尝试再次阅读答案。所有这一切,而不仅仅是第一句话。因为那正是我写的。问题是是否“匆忙”做到了,而不是匆忙可以做到。
贝尔迪尔

8

使用drush使压缩后的mysql转储

drush sql-dump --gzip --result-file

更新来自wranvaud的注释: 如果不指定结果文件,则将其存储在主目录下的:~/drush-backups/<db_name>/<timestamp>/<database_file>.sql.gz,否则可以指定--result-file ='〜/ Documents /'


1
如果不指定结果文件,它将存储在〜/ drush-backups / <db_name> / <timestamp> / <database_file> .sql.gz下的主文件夹中,否则,您可以指定--result-file='~/Documents/<my_backups_folder>'
wranvaud


2

这是使用drushAcquia-Drupal从命令行备份和还原的bash脚本解决方案:

  • 注意:您只需要在两个脚本中更改basepath,sitename以及drushpath即可满足您的需求
  • 注意2:备份脚本将创建一个.tar,其中包含您的站点文件以及描述数据库的data.sql文件
  • 注意3:还原脚本将选择由备份脚本创建的最后一个.tar备份文件

使用说明

1)在我的情况下,找到加速路径(默认情况下,加速包含在加速中)(drushpath =“ / Applications / acquia-drupal / drush”)

2)创建一个backup_ mysite文件和restore_ mysite文件,并将它们包含在您的bin文件夹路径中(例如:/ usr / local / bin)

3)编辑backup_ mysite

#!/bin/bash
# Text color variables
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow

basepath="path-to-your-server-root" #4ex "/Users/monojones/www"
backuppath="$basepath/backups"
drushpath="/Applications/acquia-drupal/drush"
sitename="your-sitename"
tempdir="$backuppath/backup_$sitename"

if [ -d $backuppath ]; then
 echo "Backup path finded. [ $backuppath ]"
else
  echo "Creating backup path... [ $backuppath ]"
  mkdir $backuppath
fi

echo "${txtylw}Backing up $sitename ... ${txtgrn}"
if [ -d "$backuppath/$sitename" ]; then
 echo "Backup subdir finded."
else
 echo "Creating $backuppath/$sitename" 
 mkdir $backuppath/$sitename
fi
echo "${txtylw}"
mkdir $tempdir
$drushpath/drush -r $basepath/$sitename  sql-dump --result-file=$tempdir/data.sql
tar -pczf $tempdir/files.tgz $basepath/$sitename $systempaths
tar -pczf $backuppath/$sitename/$sitename.backup_$(date +%Y%m%d%H%M).tar.gz $tempdir
rm -rf $tempdir

4)编辑restore_ mysite

#!/bin/bash
# Text color variables
txtred=$(tput setaf 1)    # Red
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow

basepath="path-to-your-server-root" #4ex "/Users/monojones/www"
backuppath="$basepath/backups"
sitename="your-sitename"
drushpath="/Applications/acquia-drupal/drush"

echo "${txtylw}Restoring ${txtred}$sitename ${txtylw} database: ${txtgrn}"
FILE=`ls -1 $backuppath/$sitename/$sitename.backup_* | tail -n 1`
echo "Last backup file: ${txtpur} $FILE ${txtylw}"
mkdir temp_drupalbackup_$sitename 
tar -C temp_drupalbackup_$sitename -zxvf $FILE ${backuppath:1}/backup_$sitename/data.sql
$drushpath/drush sql-drop
drush sql-cli <  temp_drupalbackup_$sitename/${backuppath:1}/backup_$sitename/data.sql
rm -R temp_drupalbackup_$sitename

1

您也可以使用sql-sync进行备份。

$ drush sql-sync -v @site1 @site2

这是备份站点的最佳方法。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.