Backup から WordPress サイトを復元する

restore コマンドは、WP STAGING の Backup から WordPress サイトを完全に復元します。ファイルを展開しデータベースをインポートする処理を 1 つの操作で行うため、サイトの移行や災害復旧に最適です。

取得できる内容

復元後:

  • すべてのファイルが復元された完全な WordPress インストール
  • インポート・構成済みのデータベース
  • ターゲット位置で利用可能なサイト

前提条件

restore コマンドには以下が必要です:

  • ターゲットパスに既存の WordPress インストール (有効な wp-config.php 付き)
  • データベース認証情報 (wp-config.php から、またはフラグで提供)
  • ターゲットディレクトリへの書き込み権限

ヒント: Docker で新しい WordPress 環境を構築するには、代わりに wpstaging add --from=backup.wpstg を使用してください。WordPress サイトのローカルコピーを作成するをご覧ください。

基本的な復元

WordPress サイトを特定のディレクトリに復元します:

wpstaging restore --path=/var/www/html backup.wpstg

または、すでに WordPress のルートディレクトリにいる場合:

cd /var/www/html
wpstaging restore backup.wpstg

リモート URL から復元する

リモートの Backup ファイルから直接復元します:

wpstaging restore --path=/var/www/html --from=https://example.com/backups/backup.wpstg

CLI は Backup をダウンロードし、検証して、1 つの操作で復元します。

Docker サイトに復元する

WP STAGING CLI の Docker 環境で管理されているサイトの場合、ホスト名を使って直接復元できます:

wpstaging restore site.local backup.wpstg

または --from フラグを使用します:

wpstaging restore site.local --from=backup.wpstg
wpstaging restore site.local --from=https://example.com/backups/backup.wpstg

要件:

  • サイトはすでに存在している必要があります (wpstaging add site.local で作成)
  • データベース認証情報はサイトの .env ファイルから自動検出されます
  • --path やデータベースフラグを指定する必要はありません

外部データベースで復元する

wp-config.php のデータベース設定を上書きして、別のデータベースサーバーに接続します:

wpstaging restore --path=/var/www/html \
  --db-host=db.example.com \
  --db-name=wordpress_db \
  --db-user=wp_user \
  --db-password=secret_password \
  backup.wpstg

データベース接続オプション

データベース接続設定の完全な制御:

フラグ説明
--db-hostデータベースホスト (例: localhost、db.example.com)
--db-nameデータベース名
--db-userデータベースユーザー名
--db-passwordデータベースパスワード
--db-socketデータベースソケットパス
--db-charsetデータベース文字セット (例: utf8mb4)
--db-collateデータベース照合順序
--db-prefixターゲット WordPress テーブル接頭辞

SSL/TLS データベース接続

セキュアなデータベース接続用:

wpstaging restore --path=/var/www/html \
  --db-host=secure-db.example.com \
  --db-ssl-ca-cert=/path/to/ca-cert.pem \
  --db-ssl-cert=/path/to/client-cert.pem \
  --db-ssl-key=/path/to/client-key.pem \
  backup.wpstg
フラグ説明
--db-ssl-ca-certCA 証明書ファイルへのパス
--db-ssl-certクライアント証明書ファイルへのパス
--db-ssl-keyクライアントキーファイルへのパス
--db-ssl-modeSSL モード (skip-verify/preferred)

上書きオプション

復元中に何が上書きされるかを制御します:

フラグデフォルト説明
--overwriteyesターゲットディレクトリのファイルを上書き
--overwrite-dbyesデータベーステーブルを上書き
--overwrite-wprootnoWordPress ルートファイルを上書き

例 – 既存のデータベースを保持する:

wpstaging restore --path=/var/www/html --overwrite-db=no backup.wpstg

例 – WordPress コアファイルも上書きする:

wpstaging restore --path=/var/www/html --overwrite-wproot=yes backup.wpstg

復元するものをフィルタリングする

extract コマンドと同じ --only-*--skip-* フラグを使用します:

Plugin と Theme のみ復元する:

wpstaging restore --path=/var/www/html --only-plugins --only-themes backup.wpstg

アップロード以外すべてを復元する:

wpstaging restore --path=/var/www/html --skip-uploads backup.wpstg

フィルターフラグの完全な一覧は Backup ファイルを展開するをご覧ください。

中断された復元を再開する

データベース復元が中断された場合、展開された SQL ファイルから再開できます:

wpstaging restore --path=/var/www/html \
  --skip-extract \
  --db-file=/path/to/extracted/database.sql \
  backup.wpstg
フラグ説明
--skip-extractファイルがすでに存在する場合、展開をスキップ
--db-fileデータベース復元に特定の SQL ファイルを使用

データベースパフォーマンスオプション

データベースインポートのパフォーマンスを微調整します:

フラグデフォルト説明
--db-batch-size1000INSERT 文あたりの行数
--db-insert-singlefalseシングル行 INSERT 文を使用
--db-timeout15sデータベース接続タイムアウト
--db-innodb-strict-modeoff復元中に InnoDB strict mode を有効化

例 – 遅いがより互換性のあるインポート:

wpstaging restore --path=/var/www/html \
  --db-insert-single \
  --db-batch-size=100 \
  backup.wpstg

復元されたファイルを検証する

復元後のファイル整合性を検証します:

wpstaging restore --path=/var/www/html --verify backup.wpstg

すべての restore フラグ

Flags:
  -o, --outputdir string          Directory for extracted files (default: ./wpstaging-output)
  -p, --path string               WordPress installation path (required)
      --site-url string           Target WordPress site URL (use if detection fails)
      --overwrite string          Overwrite target directory (yes/no) (default "yes")
      --overwrite-db string       Overwrite database (yes/no) (default "yes")
      --overwrite-wproot string   Overwrite WP root files (yes/no) (default "no")
      --db-prefix string          Target WordPress DB table prefix (use if detection fails)
      --db-innodb-strict-mode     Enable InnoDB strict mode (off by default during restore)
      --db-file string            Use the extracted backup SQL file to resume database restoration
      --db-batch-size int         Database insert batch size (default "1000")
      --db-insert-single          Use single-row INSERT statement per query
      --db-timeout string         Database connection timeout (default "15s")
      --verify                    Verify integrity of extracted files
      --skip-extract              Skip extraction if files already exist
      --from string               Backup file path or remote URL (http/https)

トラブルシューティング

データベース接続失敗

  • wp-config.php に正しいデータベース認証情報があることを確認
  • データベースサーバーが実行中でアクセス可能か確認
  • --db-* フラグで認証情報を明示的に提供してみる
  • リモートデータベースの場合、ファイアウォールが接続を許可していることを確認

権限拒否

  • ターゲットディレクトリへの書き込み権限があることを確認
  • Linux/macOS では、Web サーバーユーザーとして実行するか sudo を使う必要があるかもしれません

サイト URL の検出に失敗

CLI がサイト URL を自動検出できない場合、手動で提供してください:

wpstaging restore --path=/var/www/html --site-url=https://mysite.com backup.wpstg

次のステップ

Updated on 5月 23, 2026

Rene Hermenau

著者: Rene Hermenau

About the author: René Hermenau is the founder of WP STAGING. He works on WordPress backups, staging, migrations, database handling, and safe deployment workflows.