𝗛𝗼𝘄 𝘁𝗼 𝗕𝗮𝗰𝗸𝘂𝗽 𝗮𝗻𝗱 𝗥𝗲𝘀𝘁𝗼𝗿𝗲 𝗖𝗼𝗼𝗹𝗶𝗳𝘆 𝗶𝗻 𝟭𝟮 𝗠𝗶𝗻𝘂𝘁𝗲𝘀
Your server feels safe today. You spent hours setting up Coolify. You host your own apps, databases, and blogs. You feel in control.
Then a disaster happens. Your VPS provider shuts down your region. You run a wrong command. The server dies.
If you have no backups, you lose everything. This guide prevents that. You can set up automated backups and a full restore in 12 minutes.
Step 1: Set up S3 Storage
Coolify needs a place to store backups. Use S3-compatible storage. Cloudflare R2 is a great choice because it has zero egress fees.
You need these details from your storage provider:
- Endpoint
- Region
- Access Key
- Secret Key
- Bucket Name
In Coolify, go to the S3 Storage tab. Add your details and click Validate Connection.
Step 2: Enable Automated Backups
Go to Settings and then Backup.
- Turn on S3 Backup.
- Turn on Backup.
- Select your S3 storage source.
- Set the frequency to Daily.
Run one manual backup immediately. Check your S3 bucket to confirm the file exists.
Step 3: Save Your APP_KEY
This is the most important step. Coolify encrypts your data. If you lose this key, your backup is useless.
SSH into your server and run: cat /data/coolify/source/.env
Find the line starting with APP_KEY. Copy this value. Save it in a password manager. Do not skip this.
Step 4: Restore to a New Server
If your server dies, follow these steps on your new VPS:
- Install Coolify using the standard curl command.
- Download your .pgdump file from your S3 bucket to the new server.
- Run the restore command:
sudo docker exec -i coolify-db pg_restore --username coolify --verbose --dbname coolify < /path/to/your-backup.pgdump
You might see warnings about existing tables. Ignore them. It still works.
Step 5: Fix the 500 Error
After restoring, you might see a 500 error when clicking apps. This happens because the new server has a different APP_KEY.
To fix this:
- Open your new .env file: nano /data/coolify/source/.env
- Add this line: APP_PREVIOUS_KEYS=base64:your-old-app-key
- Save and restart Coolify using the install script.
Now your old data is readable again.
Summary Checklist:
- Set up S3 storage.
- Enable daily backups.
- Save your APP_KEY safely.
- Test a manual backup.
Self-hosting gives you control. Backups give you peace of mind.
金曜日の夜にサーバーが死ぬ前に、12分でCoolifyをバックアップして復元する方法
誰もが経験したことがあるはずです。金曜日の夜、リラックスしようとしているその時、突然……サーバーがダウンするのです。
Coolifyは素晴らしいセルフホスト型PaaSですが、万が一の事態に備えてバックアップを取っておくことは不可欠です。この記事では、非常にシンプルかつ迅速なバックアップと復元方法を解説します。
Coolifyのデータはどこにあるのか?
Coolifyのすべての設定、データベース、および構成は、サーバー上の /data/coolify ディレクトリに保存されています。つまり、このディレクトリを丸ごとバックアップすれば、すべてのデータが守られるということです。
バックアップの手順
バックアップは非常に簡単です。以下の手順に従ってください。
1. サーバーにSSHで接続する
まず、SSHを使用してサーバーにログインします。
2. バックアップの作成
以下のコマンドを実行して、/data/coolify ディレクトリを圧縮アーカイブとして作成します。
sudo tar -cvzf coolify-backup.tar.gz /data/coolify
3. バックアップをリモートに転送する
作成した coolify-backup.tar.gz ファイルを、サーバー本体ではなく、安全なリモートストレージ(AWS S3、Cloudflare R2、あるいは別のサーバーなど)に転送してください。
例えば、rclone を使用している場合は以下のようになります。
rclone copy coolify-backup.tar.gz remote:my-backup-bucket
復元の手順
サーバーがクラッシュし、新しいサーバーを用意した場合は、以下の手順で復元を行います。
1. Coolifyをインストールする
まず、新しいサーバーにCoolifyを通常通りインストールします。
curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash
2. Coolifyを停止する
データの整合性を保つため、復元を行う前にCoolifyのコンテナを停止する必要があります。
docker stop $(docker ps -q)
(注: すべてのコンテナを停止したくない場合は、Coolifyに関連するコンテナのみを特定して停止してください)
3. 既存のデータを削除してバックアップを展開する
次に、現在の /data/coolify ディレクトリを削除し、バックアップからデータを復元します。
sudo rm -rf /data/coolify
sudo tar -xvzf coolify-backup.tar.gz -C /
4. Coolifyを再起動する
最後に、Coolifyを起動します。
# インストールスクリプトを再度実行するか、docker compose を使用して起動します
まとめ
バックアップは、問題が起きてから考えるものではなく、事前に準備しておくものです。この手順を自動化(cronなどを使用)しておけば、金曜日の夜に安心して眠りにつくことができるでしょう。