Developer Services Portal 4.17.09 版
本文說明如何使用 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 網站根目錄。預設的 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 --clean --dbname=devportal --host=localhost --username=apigee < /tmp/portal.bak
如要從備份還原並建立新的資料庫,請使用下列指令:
pg_restore --clean --create --dbname=devportal --host=localhost --username=apigee < /tmp/portal.bak
您也可以將備份檔案還原至 Drupal 網頁根目錄和私人檔案。