WordPressのバックアップとリストア
投稿者:yasu 更新日時:2010年6月3日 16時49分17秒カテゴリ:CentOS, Linux, MySQL, Windows, Windows Web Server 2008 R2, WordPress, 自宅サーバー
当ブログは現在Windows Web Server 2008 R2にWordPressをインストールして稼働しています。
元々はCentOS5で稼働させていたのだけれど、インストールマニアックス3に応募して借りているサーバー機をタダでもらうにはWindows Web Server 2008 R2で構築したWebサーバーを80番ポートで1年間公開しないといけない。
1年公開し終わったらWordPressをCentOSの環境に戻したいと思っているので、今の内にWindowsからCentOSに戻る手順を確立しておこうかと思います。
Windows Web Server 2008 R2側の作業
MySQLのバックアップ
コマンドプロンプトからMySQLのバックアップを行います。
Enter password: mysqlのrootユーザのパスワード
mysqldumpのオプション
-B wordpress・・・WordPressのデータベース名
-h localhost・・・WordPressデータベースがあるMySQLサーバーのサーバー名
-u root・・・MySQLのユーザ名
-p・・・上記ユーザのログインパスワード
--opt・・・オプション--add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charsetと同等
-r wordpress.db.bak・・・Windowsの場合改行コードが\r\nになるのを防止する(Linuxに移行するので必要かと思った)
WordPressのバックアップ
エクスプローラからWordPressのバックアップを行います。
C:\inetpub\wwwroot\blog フォルダをblog.zipの名前でアーカイブします。
※上記WordPressフォルダ(C:\inetpub\wwwroot\blog)は各自の環境にあわせて読み替えてください
バックアップファイルの転送
wordpress.db.bakとblog.zipをCentOSの/rootディレクトリ(どこでもよいです)にコピーします。
CentOS 5 側の作業
WordPressをリストア
WordPressをリストアします。
[root@centos ~]# cp blog.zip /var/www/html/
WordPressのバックアップファイルを解凍します
[root@centos ~]# unzip /var/www/html/blog.zip
WordPressフォルダ(ここでは名前がblogとなっていますがWordPressが入っています)の所有者を変更します
[root@centos ~]# chown -R apache.apache blog
WordPressのバックアップファイルを削除します
[root@centos ~]# rm -f /var/www/html/blog.zip
MySQLのリストア
MySQLをリストアします。
[root@centos ~]# mysql -u root -p
Enter password: MySQLのrootユーザのパスワード
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> drop database wordpress;
Query OK, 11 rows affected (0.13 sec)
mysql> create database wordpress;
Query OK, 1 row affected (0.05 sec)
mysql> grant all privileges on wordpress.* to wordpress@localhost identified by 'wordpressユーザのパスワード';
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye
作り直したWordPress用データベースにデータをリストアします
[root@centos ~]# mysql -h localhost -u root -p wordpress < wordpress.db.bak
Enter password: MySQLのrootユーザのパスワード
リストアが正常に完了しているかテーブル一覧を確認します
[root@centos ~]# mysql -h localhost -D wordpress -u root -p
Enter password: MySQLのrootユーザのパスワード
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show tables;
+-----------------------+ | Tables_in_wordpress | +-----------------------+ | wp_commentmeta | | wp_comments | | wp_links | | wp_options | | wp_postmeta | | wp_posts | | wp_term_relationships | | wp_term_taxonomy | | wp_terms | | wp_usermeta | | wp_users | +-----------------------+
11 rows in set (0.00 sec)
これでCentOSにWordPressのリストアは完了です。
なお現状yasuの環境ですとCentOSは別のポートで公開しています。
このままですとCentOS側のWordPressのログインをしようとしてもWindows側のWordPressに飛んでいってしまうので、サイトURL設定を変更します。
+-------------+-----------------------------+ | option_name | option_value | +-------------+-----------------------------+ | home | http://www.sa-sa-ki.jp/blog | | siteurl | http://www.sa-sa-ki.jp/blog | +-------------+-----------------------------+
2 rows in set (0.00 sec)
mysql> update wp_options set option_value = 'https://sa-sa-ki.jp:8443/blog' where option_name = 'siteurl';
mysql> update wp_options set option_value = 'https://sa-sa-ki.jp:8443/blog' where option_name = 'home';
これで別ポートで公開しているCentOS側のWordPressでログインできるようになりました。

