Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ that only restate the release note above them.

### Fixed

- **`roll restore` and `roll pull` no longer litter the project with `*.backup.<epoch>` 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.
- **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 `<env>-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`.
Expand Down
10 changes: 10 additions & 0 deletions docs/backup-restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- <file>`; 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 `<file>.backup.<epoch>` 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:
Expand Down
42 changes: 28 additions & 14 deletions utils/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,27 @@ function performLegacyMigration() {
fi
}

## decryptConfigInto <encrypted source> <target path>
## 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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -667,22 +688,15 @@ 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
# `<file>.backup.<epoch>` 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
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"
Expand Down
Loading