WordPress 1.5 備份/還原的解決方案

建置部落格的人最害怕的大概有兩個 — Blog 搬家跟資料庫毀損.

如果是用外面免費的 blog 空間, 最煩惱的就是要搬家了, 因為使用者無法進入資料庫, 也不知道資料庫的格式 (schema), 搬家只能用手工一篇一篇搬, 而且這種搬法會使得回應全部遺失, 很可惜, 像前一陣子 大中小圓 那裡搬家, 很辛苦. 如果你真的很強, 還有一個方式是用 RSS 把文章回應都弄出來, 再想辦法 “灌”到新系統… 可是外面的免費 blog 好像沒什麼方法灌, 想得到的只有 email post, 但也要那個系統有支援才行.

用 WordPress 或 Movable Type 之類的 blog 好一點, 可以用一些方法把資料庫 “倒” 出來, 復原時再整個 “灌” 回去就好了, 回應也都不會遺失. 且一般不同系統, 為了廣拉用戶, 都會提供不同系統之間資料庫的轉換, 所以基本上換系統也不是不可行. 只是一般用戶不懂 SQL 語法, 還是沒辦法作備份/還原.

weblogtoolscollection.com 那裡 有一個 WordPress 備份的解決方案–Backup Plugin for WordPress 1.5 (又稱One-Click Backup for WP 1.5), 它是一個 plugin, 已經出來有一陣子了, 不是什麼新鮮的但是還是報給用 WordPress 的同好知道. 依說明裝上 plugin, activate 之後, 管理畫面會多一個選項 Backup/Restore :

裡面有一個按鍵:

按下去,幾秒鐘就好了, 好快 :clap:, 包含了所有的文章,回應,分類等等. 備份的檔案是 “日月年wordpress.sql”, 例如 26052005wordpress.sql

因為我是在 local 作, 所以其他的 “download” “Backup WordPress Files” 都不用也沒試過, 只要把整個 WordPress 目錄(含那個 .sql) 用 winzip 或 winrar 壓縮然後 copy 到別的地方保存起來就完成了.

Restore 倒是有些問題, 按上面那個 “Restore Database” button 不 work, 是不是 Win32 系統的緣故? unix 的系統也許不會有問題. 不過, 只要用下面一行命令就可以了, 不用擔心.
mysql -u用戶名 -p密碼 -f 資料庫名稱 < 檔名
例如
mysql -uroot -pxxx -f wpblog < 26052005wordpress.sql

經過驗證,中文沒問題.

PS. 如果按 Backup/Restore 時有問題, 把 backuprestore.php 第 13 行
add_menu_page('Backup/Restore', 'Backup/Restore', 9, dirname(__FILE__) . '/backuprestoreAdmin.php');
改成
add_menu_page('Backup/Restore', 'Backup/Restore', 9, '/backuprestoreAdmin.php');

UPDATE — 2/11/2007

上面這個 plugin 已經沒有維護了,另一個備份的 plugin 是
For 1.x
For 2.1版
2.0.x版內建就是這個版本,但2.1又拿掉了.

(Visited 9,982 times, 1 visits today)

在〈WordPress 1.5 備份/還原的解決方案〉中有 26 則留言

  1. mark,可以問白痴問題嗎?
    今天到你家看嚇了一大跳–右邊連結的字大到畫面裝不下了!
    可是左邊的內文字體並沒變大,不過標題也變大了
    平常一頁就簡單明瞭的東東,今天要一直捲一直捲才看得完
    去別家也發現字體都變大了
    我想這是我家電腦出了問題,可是不知道怎麼解決說

    回覆
  2. Mark,

    又得請教你問題了。

    我剛用Backup Plugin for WordPress 1.5來備份試說新語的tables. 一切很順利就完成,產生一個帶有時間標記的.sql檔案。

    問題就出在還原,我用phpMyAdmin在我local機器上做,結果MySQL丟給我如下的錯誤訊息:
    #1064 – You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘DEFAULT CHARSET=utf8’ at line 13
    我的MySQL是4.0.24版,不曉得是不是這個版本的語法有出路?

    回覆
  3. Mark,

    Sorry for using English to reply. I am in office and can’t type Chinese.

    I did use the mysql command you provided as well as phpMyAdmin to restore the tables. Both returned the same error message to me after trying to create wp_categories table. Line 13 is simply a SQL statement to create wp_categories table in MySQL.

    I did a search on Google and found someone commented that MySQL 4.1.* could support the syntax “DEFAULT CHARSET=utf8” at the end of table creation syntax. Not sure if this is true or not.

    回覆
  4. Mark,

    Below is the table creation statement on Line 13:

    CREATE TABLE `wp_categories` (
    `cat_ID` bigint(20) NOT NULL auto_increment,
    `cat_name` varchar(55) NOT NULL default ”,
    `category_nicename` varchar(200) NOT NULL default ”,
    `category_description` longtext NOT NULL,
    `category_parent` int(4) NOT NULL default ‘0’,
    PRIMARY KEY (`cat_ID`),
    KEY `category_nicename` (`category_nicename`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

    回覆
  5. 剛試了
    mysql>
    mysql> CREATE TABLE `wp_categories` (
    -> `cat_ID` bigint(20) NOT NULL auto_increment,
    -> `cat_name` varchar(55) NOT NULL default ‘ ‘,
    -> `category_nicename` varchar(200) NOT NULL default ‘ ‘,
    -> `category_description` longtext NOT NULL,
    -> `category_parent` int(4) NOT NULL default ‘0’,
    -> PRIMARY KEY (`cat_ID`),
    -> KEY `category_nicename` (`category_nicename`)
    -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
    Query OK, 0 rows affected (0.06 sec)

    mysql> drop table wp_categories;
    Query OK, 0 rows affected (0.00 sec)

    看來是版本MySQL的問題…我用 4.1.10a on Traditional Chinese Windows system.

    3 Solutions:
    1.Upgrade mysql 🙂
    2.Remove ‘DEFAULT CHARSET=utf8’ by using edtor. Someone said it is supported since 4.1.1
    3.Try 文興’s suggestion, if no 亂碼.

    回覆
  6. Mark,

    After upgrading MySQL to 4.1.10, the restoration process (using mysql command line) on my local PC works perfectly. The Traditional Chinese characters are also showing without any issue. Hence, we can safely conclude that the version of MySQL will definitely decide if the backup/restore process is successful or not.

    Thanks for all the assistance you and 文興 have provided.

    回覆
  7. Great to see that 喬爹 can now backup database.

    My blog is hosted by a provider, here is the server info:
    operating system: FreeBSD 4.8-RELEASE-p24
    mysql version: mysql Ver 12.22 Distrib 4.0.16
    perl version: perl, v5.8.3
    php version: PHP 4.3.8 (detailed PHP information)

    回覆
  8. I have just used phpMyAdmin to backup the entire database, then restore it to another new database. Finally, I linked WP to the new database. It works even with MySQL 4.0.16. Maybe it was a problem with both OS and MySQL.

    回覆

發佈留言