drush 安装/Install

Windows 上面安装Drush
GITHUB: https://github.com/drush-ops/drush
官方的安装文档:http://www.drush.org/drush_windows_installer
包下载: http://www.drush.org/sites/default/files/attachments/Drush-6.0-2013-08-28-Installer-v1.0.21.msi

Linux

pear channel-discover pear.drush.org
pear install drush/drush

详细请看GITHUB文档

Linux 删除Drush / 重新安装

$sudo pear uninstall drush/drush
$sudo pear install drush/drush-5.0.0
$sudo pear upgrade-all

Drush 常用操作

drush dl Module 下载一个模块
  --dev 下载开发版本
  --select 提供所有版本列表,让你选择要下载的版本

drush en Module 启用一个模块
drush dis Module 禁用一个模块
drush pm-uninstall 删除一个模块

drush up drupal 升级drupal核心
drupal up  升级drupal模块
drupal up 检查更新所有模块

drush cc all 清空所有缓存
drush upwd --password="123" admin 修改admin用户的密码

Archlinux drush 错误

$ drush
The following restricted PHP modes have non-empty values:            [error]
open_basedir. This configuration is incompatible with drush.  Please
check your configuration settings in /etc/php/php.ini or in your
drush.ini file; see examples/example.drush.ini for details.
file_exists(): open_basedir restriction in effect. File(/etc/drush/drushrc.php) is not within the allowed path(s):                         [warning]
(/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/pear/drush/:/etc/drush/:/root/) context.inc:150
file_exists(): open_basedir restriction in effect. File(/etc/drush/drush5rc.php) is not within the allowed path(s):                        [warning]
(/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/pear/drush/:/etc/drush/:/root/) context.inc:150
is_dir(): open_basedir restriction in effect. File(/usr/share/drush/commands) is not within the allowed path(s):                           [warning]
(/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/pear/drush/:/etc/drush/:/root/) command.inc:1289
Execute a drush command. Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.

在Arch Linux中. 安装drush后, 是能正常使用,但是会出现这样的错误

解决办法:
http://drupal.org/node/509506
http://drupal.stackexchange.com/questions/4088/drush-open-basedir-restriction-in-effect-on-media-temple

$cp /etc/php/php.ini ~/.drush/
$vim ~/.bashrc 

//添加
alias drush='/usr/bin/php -c ~/.drush/php.ini /usr/share/pear/drush/drush.php'

//编辑你copy的php.ini
$vim ~/.drush/php.ini

//将open_basedir 设置为空
open_basedir = 

Drupal Drush and Hook/API

无意中打开 views/drush/views.drush.inc看到

/**
 * Implement hook_drush_command().
 */
views_drush_command

原来views 中定义着两个drush hook

hook_drush_help
hook_drush_common

这里有更多的drush hook
http://api.drush.org/api/drush/docs%21drush.api.php/5.x

drush api:
http://api.drush.org/api/drush

接着试着运行一下里面的定义:

使用drush 修改密码:

$drush user-password admin --password="123"

drupal 数据库备份与恢复

用Drush备份:

drush -v sql-dump --result-file=back.sql

使用脚本按日期来备份

#!/bin/bash
now=$(date +%Y-%m-%d-%H-%M-%S)
drush -v sql-dump --result-file=./mysqlback/$now.sql

用bam-backup来备份,首先我只能说backup_migrate这是一个非常好的模块.用来备份和恢复必备良器。先来安装这个模块

$drush dl backup_migrate
$drush en backup_migrate y

使用bam-backup来备份,首先你要设置你的私有目录.然后才能运行以下命令否则会出错.文件会自动备份到你的私有目录backup_migrate/manual/

$drush bam-backup

恢复备份.

http://drupal.org/node/681284

这个备份的名字你其实可以在你的任意目录下面运行。他都可以去找到你的备份文件

$drush bam-restore db manual you_db_2012-11-30T01-29-41.mysql.gz

如果在你不知道到你最新的备份是哪个的情况下那你可能只能用脚本了. 首先本次是恢复最新的备份

#!/bin/bash
lastfile=$(ls -t1 ./you_private/backup_migrate/manual/ | head -n1)
drush bam-restore db manual --yes "$lastfile"

恢复最老的备份:

#!/bin/bash
lastfile=$(find ./you_private/backup_migrate/manual/ -not -type d -printf "%p\n" | sort -n | tail -1)
drush bam-restore db manual --yes "$lastfile"

使用mysql的方法备份与恢复

备份使用mysqldump,用户名和密码都是root

$mysqldump -uroot -proot mydatabase > mydatabase.sql

恢复

$mysql -uroot -proot mydatabase < mydatabase.sql

Drupal 常用模块安装

#!/bin/bash
 
enable_modules=('admin_menu' 'module_filter' 'token' 'ctools' 'pathauto' 'ds' 'devel' 'views' 'context')
disable_modules=('firephp' 'overlay' 'toolbar' 'color' 'dashboard')
 
for dmodule in ${disable_modules[@]}; do
    sudo drush pm-disable $dmodule -y
done
 
for emodule in ${enable_modules[@]}; do
   sudo drush dl $emodule -y
done;
 
for emodule in ${enable_modules[@]}; do
   sudo drush pm-enable $emodule -y
done;