Developer Services Portal 4.17.05 版
本文件說明如何使用 Postgres pg_dump 和 pg_restore 指令,在入口網站的安裝過程中備份及還原工作。
備份之前
您可以使用入口網站安裝設定檔中的 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 - 備份 Drupal 資料庫執行個體。pg_dump 指令會建立資料庫副本:
pg_dump --dbname=devportal --host=192.168.56.101 --username=drupaladmin --password --format=c > /tmp/portal.bak
- dbname 會指定入口網站安裝設定檔中 PG_NAME 屬性指定的資料庫名稱。
- host 指定入口網站節點的 IP 位址。
- username 用於指定入口網站使用的 Postgres 使用者名稱,以存取入口網站安裝設定檔中 DRUPAL_PG_USER 屬性指定的資料集。
- 系統會提示您輸入 Postgres 使用者密碼,這是入口網站安裝設定檔中 DRUPAL_PG_PASS 屬性所定義的密碼。
- 備份整個 Drupal 網路根目錄。
預設安裝位置為 /opt/apigee/apigee-drupal,但你可能已變更。
如果無法確定這個目錄的位置,請使用「Drush status」指令或「Drupal」選單中的「Configuration」>「Media」>「File」項目,確定公開檔案系統的位置和私人檔案系統路徑 (請參閱下一個步驟)。 - 備份 /opt/apigee/data/apigee-drupal-devportal/private 中的檔案。
還原入口網站
如要從備份還原至現有資料庫,請使用下列指令:
pg_restore --clean --dbname=devportal --host=localhost --username=apigee < /tmp/portal.bak
如要從備份還原並「建立新資料庫」,請使用下列指令:
pg_restore --clean --create --dbname=devportal --host=localhost --username=apigee < /tmp/portal.bak
您也可以將備份檔案還原至 Drupal 網路根目錄和私人檔案。