本節說明如何使用 Postgres pg_dump
和 pg_restore
指令備份及還原 Apigee Developer Services 入口網站 (或簡稱入口網站) 的地端部署安裝項目。
備份前的準備
在備份入口網站之前,您必須知道入口網站的資料庫名稱。
入口網站安裝設定檔中的 PG_NAME
屬性會指定入口網站資料庫的名稱。入口網站安裝操作說明中的範例設定檔使用「devportal」名稱。如果不確定資料庫名稱,請查看設定檔,或使用以下 psql
指令顯示資料庫清單:
psql -h localhost -d apigee -U postgres -l
其中 -U
會指定入口網站用來存取資料庫的 Postgres 使用者名稱。這是入口網站安裝設定檔中 DRUPAL_PG_USER
屬性的值。系統會提示您輸入資料庫密碼。
這個指令會顯示下列的資料庫清單:
Name | Owner | Encoding | Collate | Ctype | Access privileges -------------+--------+----------+-------------+-------------+--------------------- apigee | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/apigee + | | | | | apigee=CTc/apigee + | | | | | postgres=CTc/apigee devportal | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | newportaldb | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/apigee + | | | | | apigee=CTc/apigee template1 | apigee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/apigee + | | | | | apigee=CTc/apigee
備份入口網站
如何備份入口網站:
- 預設為 Drupal 目錄 (
/opt/apigee/apigee-drupal
):cd /opt/apigee/apigee-drupal
- 使用
pg_dump
指令備份 Drupal 資料庫執行個體:pg_dump --dbname=portal_db --host=host_IP_address --username=drupaladmin --password --format=c > /tmp/portal.bak
在此情況下:
- portal_db 是資料庫名稱。這是入口網站安裝設定檔中的
PG_NAME
屬性。如果您不確定資料庫名稱,請參閱備份之前。 - host_IP_address 是入口網站節點的 IP 位址。
- drupaladmin 是入口網站用來存取資料庫的 Postgres 使用者名稱。您必須使用入口網站安裝設定檔中的
DRUPAL_PG_USER
屬性來定義這個屬性。
當
pg_dump
提示您輸入 Postgres 使用者密碼時,請使用您在入口網站安裝設定檔中透過DRUPAL_PG_PASS
屬性指定的密碼。pg_dump
指令會建立資料庫副本。 - portal_db 是資料庫名稱。這是入口網站安裝設定檔中的
- 備份整個 Drupal 網路根目錄。預設的 webroot 位置為
/opt/apigee/apigee-drupal/wwwroot
。 - 備份公開檔案。這些檔案預設位於
/opt/apigee/apigee-drupal/wwwroot/sites/default/files
。 如果正確位置,系統會在步驟 3 備份這些項目。如果您已將其從預設位置移至其他位置,則必須明確將其上移。 - 備份
/opt/apigee/data/apigee-drupal-devportal/private
中的私人檔案。如果不確定這個目錄的位置,請使用
drush status
指令判斷私人檔案系統的位置,
還原入口網站
完成入口網站備份後,即可使用 pg_restore
指令從備份還原。
如要從備份還原到現有資料庫,請使用下列指令:
pg_restore --clean --dbname=portal_db --host=localhost --username=apigee < /tmp/portal.bak
如要從備份還原並「建立新資料庫」,請使用下列指令:
pg_restore --clean --create --dbname=portal_db --host=localhost --username=apigee < /tmp/portal.bak
您也可以將備份檔案還原至 Drupal 網路根目錄和私人檔案。