.env.backup.production — |verified|
So open your terminal right now. Navigate to your production server. Type:
cp .env.backup.production .env.production systemctl restart app In under 10 seconds, the disaster is over. Simply duplicating the file as cp .env.production .env.backup.production is not enough. A robust .env.backup.production strategy involves three distinct layers of protection. 1. Immutability (Read-Only Mode) Your live .env.production may be writable by the application process (e.g., for runtime migrations or feature flags). Your backup should never be writable by the app user.
cp .env.backup.production .env.production .env.backup.production
Here is a production-grade cron job (or systemd timer) that should run every 6 hours on your production host:
| Feature | .env.example | .env.backup.production | | :--- | :--- | :--- | | | No (uses DB_PASSWORD=changeme ) | Yes (contains actual database password) | | Can be committed to git | Yes (safe) | Never (unsafe unless encrypted) | | Restores a live system | No (requires manual entry of secrets) | Yes (one command restore) | | Backup rotation needed | No | Yes | So open your terminal right now
For production systems, this is typically named .env.production . But ask any seasoned Site Reliability Engineer (SRE) who has survived a "wipeout" scenario, and they will tell you that the most important file in their disaster recovery arsenal isn't the live one—it is the .
But a team with a strict backup protocol does the following: Simply duplicating the file as cp
export ENV_BACKUP_PATH="$APP_HOME/.env.backup.production" If .env.backup.production is your only backup, you have no safe environment to test the restoration process.