From 49cc35263f404aadda4ca2d52fd3816050afebba Mon Sep 17 00:00:00 2001 From: Marc Bekhuis Date: Mon, 9 Nov 2026 13:56:53 +0100 Subject: [PATCH 1/2] restore: stop writing *.backup. copies into the project restoreConfigurations saved every file it was about to overwrite as `.backup.` next to it, so each `roll pull` whose archived .env.roll, env.php, auth.json or composer.lock differed from the local copy left another file in the project root and app/etc: credentials included, 1.3 MB per composer.lock, and usually hidden by the project's .gitignore. Nobody used them. .env.roll and composer.* are tracked and come back with `git checkout`, and after a pull the archived env.php and auth.json are the ones wanted. The restore now overwrites without keeping a copy. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +++++++ docs/backup-restore.md | 10 ++++++++++ utils/backup.sh | 17 +++++------------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1fe213..fd22023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,13 @@ that only restate the release note above them. ### Fixed +- **`roll restore` and `roll pull` no longer litter the project with `*.backup.` files.** + Before overwriting `.env.roll`, `app/etc/env.php`, `auth.json`, `composer.json` or + `composer.lock` with the archived copy, the restore saved the old file beside it, so every pull + whose files differed from the build server's left another copy in the project root and `app/etc` + (1.3 MB per `composer.lock`, credentials in `env.php` and `auth.json`), usually hidden by the + project's `.gitignore`. The restore now overwrites without a copy: tracked files come back with + `git checkout`, and after a pull the archived `env.php` and `auth.json` are the ones wanted. - **RedisInsight's preset connection reaches the store.** It pointed at `-redis`, a container hostname only the Redis fragment sets, so it did not resolve when Dragonfly or Valkey ran the service; it now uses the service name `redis`. diff --git a/docs/backup-restore.md b/docs/backup-restore.md index da89b05..9aec065 100644 --- a/docs/backup-restore.md +++ b/docs/backup-restore.md @@ -204,6 +204,16 @@ The system automatically backs up relevant configuration files: - `config/database.yml` - Rails database configuration - Other framework-specific configuration files +### Files a Restore Replaces + +`roll restore` (and `roll pull`, which runs it) writes the archived copies over the project's own +files without keeping the old ones. Tracked files such as `.env.roll`, `composer.json` and +`composer.lock` come back with `git checkout -- `; for untracked ones such as +`app/etc/env.php` and `auth.json`, copy anything you want to keep before restoring. + +Earlier versions saved every overwritten file as `.backup.` next to it. Those leftovers +can be deleted; `find . -maxdepth 3 -name '*.backup.[0-9]*' -not -path './vendor/*'` lists them. + ## Metadata and Integrity Each backup includes comprehensive metadata: diff --git a/utils/backup.sh b/utils/backup.sh index 1a7a056..74a6b11 100644 --- a/utils/backup.sh +++ b/utils/backup.sh @@ -667,18 +667,11 @@ function restoreConfigurations() { # Create target directory if needed mkdir -p "$(dirname "$target_path")" - # Backup existing file if it exists - if [[ -f "$target_path" ]]; then - if [[ $is_encrypted == true ]]; then - # For encrypted files, we can't easily compare so always backup - cp "$target_path" "$target_path.backup.$(date +%s)" - logMessage INFO "Backed up existing $relative_path" - elif ! cmp -s "$config_file" "$target_path"; then - cp "$target_path" "$target_path.backup.$(date +%s)" - logMessage INFO "Backed up existing $relative_path" - fi - fi - + # The existing file is overwritten without keeping a copy. Restores used to save it as + # `.backup.` beside the original, so every `roll pull` whose archived + # .env.roll, env.php, auth.json or composer.lock differed left more of them in the project + # root and app/etc (credentials included). Nobody used them: the tracked files come back + # with `git checkout`, and for env.php and auth.json the archived copy is the one wanted. if [[ $is_encrypted == true ]]; then # Decrypt the file if [[ -n "$RESTORE_DECRYPT" ]]; then From bad187dae99768ae4f7b7117e82d16abb8ef86a3 Mon Sep 17 00:00:00 2001 From: Marc Bekhuis Date: Mon, 9 Nov 2026 14:28:43 +0100 Subject: [PATCH 2/2] restore: decrypt config into a temp file before replacing the target `gpg --decrypt ... > "$target_path"` truncated the target before decryption started, so a wrong passphrase or a damaged archive left an empty env.php or auth.json. With the pre-restore copies gone that was unrecoverable. decryptConfigInto decrypts into a mktemp file next to the target and writes the target only on success (cat, so its owner and mode stay), for both the structured and the legacy backup layout. Raised by Copilot on epartment/rolldev#21. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ utils/backup.sh | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd22023..b2b09bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ that only restate the release note above them. (1.3 MB per `composer.lock`, credentials in `env.php` and `auth.json`), usually hidden by the project's `.gitignore`. The restore now overwrites without a copy: tracked files come back with `git checkout`, and after a pull the archived `env.php` and `auth.json` are the ones wanted. +- **A failed decryption no longer empties `env.php` or `auth.json`.** Encrypted configuration was + decrypted straight into the target, which the shell truncates before gpg runs, so a wrong + passphrase or a damaged archive left an empty file. It now decrypts into a temporary file and + writes the target only on success. - **RedisInsight's preset connection reaches the store.** It pointed at `-redis`, a container hostname only the Redis fragment sets, so it did not resolve when Dragonfly or Valkey ran the service; it now uses the service name `redis`. diff --git a/utils/backup.sh b/utils/backup.sh index 74a6b11..63846fb 100644 --- a/utils/backup.sh +++ b/utils/backup.sh @@ -571,6 +571,27 @@ function performLegacyMigration() { fi } +## decryptConfigInto +## Decrypt into a private temporary file next to the target and write the target only once gpg has +## succeeded. Redirecting gpg straight into the target truncated it before decryption started, so a +## wrong passphrase or a damaged archive left an empty env.php or auth.json, and the restore keeps no +## copy of the original. `cat >` rather than `mv` keeps the target's own owner and mode. +function decryptConfigInto() { + local source_file="$1" target_path="$2" tmp_file="" + + tmp_file="$(mktemp "${target_path}.restore.XXXXXX")" || return 1 + + if echo "$RESTORE_DECRYPT" | gpg --batch --yes --quiet --passphrase-fd 0 --decrypt "$source_file" > "$tmp_file" \ + && cat "$tmp_file" > "$target_path" + then + rm -f "$tmp_file" + return 0 + fi + + rm -f "$tmp_file" + return 1 +} + function restoreConfigurations() { local backup_path="$1" local step="$2" @@ -621,7 +642,7 @@ function restoreConfigurations() { if [[ $is_encrypted == true ]]; then # Decrypt the file directly to target location if [[ -n "$RESTORE_DECRYPT" ]]; then - if echo "$RESTORE_DECRYPT" | gpg --batch --yes --quiet --passphrase-fd 0 --decrypt "$source_file" > "$target_path"; then + if decryptConfigInto "$source_file" "$target_path"; then logMessage INFO "Decrypted and restored $file" else logMessage ERROR "Failed to decrypt $file" @@ -675,7 +696,7 @@ function restoreConfigurations() { if [[ $is_encrypted == true ]]; then # Decrypt the file if [[ -n "$RESTORE_DECRYPT" ]]; then - if echo "$RESTORE_DECRYPT" | gpg --batch --yes --quiet --passphrase-fd 0 --decrypt "$config_file" > "$target_path"; then + if decryptConfigInto "$config_file" "$target_path"; then logMessage INFO "Decrypted and restored $relative_path" else logMessage ERROR "Failed to decrypt $relative_path"