wp-cli で改竄されてないか確認できるよ。
$ cd /path/to/wordpress
$ wp core verify-checksums
wp-cli で改竄されてないか確認できるよ。
$ cd /path/to/wordpress
$ wp core verify-checksums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tables=$(wp db query "show tables;" | grep -v "Tables_in") | |
for table in ${tables}; do | |
echo "— ${table}" | |
# エクスポート処理 | |
wp db export ${table}.sql –tables=${table} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
wp_root="/path/to/wordpress" | |
wp="wp –path=${wp_root}" | |
hooks=`${wp} cron event list –format=json | jq -r '.[] | select(.next_run_relative == "now") | .hook'` | |
for hook in ${hooks} ; do | |
echo "***** run event ${hook} *****" | |
${wp} cron event run ${hook} | |
echo "" | |
done |
jq 便利すなぁ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
find /var/www/vhosts/ -maxdepth 2 -type f -name wp-config.php | while read thisfile; do | |
wp_path=${thisfile%/*} | |
echo "***** ${wp_path}" | |
wp_version=`wp –path=${wp_path} core version` | |
wp_home=`wp –path=${wp_path} eval "echo home_url();"` | |
echo "${wp_home} : ${wp_version}" | |
done; |
while ループ内で wp core update とかをすれば、一撃ですべての WordPress をアップデートできるよ
名前もお好きに、とりあえず、wp_update_siteurl.sh とかで。EC2のメタデータを取得して、その情報でデータベースを更新するようにしました。
#!/bin/bash _id=`curl -s 169.254.169.254/latest/meta-data/instance-id/ | sed -e "s/-/_/"` _dns=`curl -s 169.254.169.254/latest/meta-data/public-hostname/` mysql -u root ${_id} <<_EOT_ update wp_options set option_value = 'http://${_dns}' where option_name = 'siteurl'; update wp_options set option_value = 'http://${_dns}' where option_name = 'home'; _EOT_
武田さん、ありがとうございます。
でも、このままだと不完全で、実は WordPress では wp_options の他にも wp_posts 内に画像ファイルのURLとかを投稿した時の home_url を元に絶対パスで保存してたりするんです。
wp-cli ってツールを使うと、そんな値を一括で置換してくれる search-replace という便利なコマンドが有ります。
網元AMIには、最初から wp-cli 入っているので、wp-cli をインストールしたりする必要は無いです。
てことで、こんな感じで wp_update_siteurl.sh を作ればおっけー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WP_ROOT="/path/to/wordpress" | |
WP_CLI="/usr/local/bin/wp –path=${WP_ROOT}" | |
_old_url=`${WP_CLI} eval "echo home_url();"` | |
_dns=`curl -s 169.254.169.254/latest/meta-data/public-hostname/` | |
$WP_CLI search-replace ${_old_url} http://${_dns} |
2行目の “/path/to/wordpress” の所は、適宜自分の環境に合わせて変更してください。
wp-cli 使えば、パスワードがわからなくなったユーザのパスワードを変更することも容易です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd /path/to/wordpress | |
$ wp user list | |
+—–+—————–+————————–+———————————+———————+—————+ | |
| ID | user_login | display_name | user_email | user_registered | roles | | |
+—–+—————–+————————–+———————————+———————+—————+ | |
| 1 | hogehoge | hogehoge | hogehoge@example.com | 2014-03-20 00:00:00 | administrator | | |
+—–+—————–+————————–+———————————+———————+—————+ | |
$ wp user update 1 -user_pass=fugafuga | |
Success: Updated user 1. |
参考
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml | |
cd /path/to/wordpress/ | |
wp plugin install wordpress-importer –activate | |
wp import –authors=create ~/theme-unit-test-data.xml |
$ cd /path/to/wordpress
$ wp export --post_type=page