-
Notifications
You must be signed in to change notification settings - Fork 0
feat: exclude regenerable cache directories from hosting backups #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| namespace Deployer; | ||
|
|
||
| /** | ||
| * Release-local directories that are fully regenerated on every deploy (composer/npm install, | ||
| * cache warmup) and therefore don't need to be part of a hosting backup. | ||
| */ | ||
| set('backup_exclude_dirs', [ | ||
| 'vendor', | ||
| 'var/cache', | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace Deployer; | ||
|
|
||
| // Cache Directory Tagging Specification (https://bford.info/cachedir/), honored by | ||
| // Mittwald's hosting backups as well as tools like rsync/borg/restic --exclude-caches. | ||
| const CACHEDIR_TAG_SIGNATURE = 'Signature: 8a477f597d28d172789f06886806bc55'; | ||
|
|
||
| task('backup:exclude_cache', function () { | ||
| foreach (get('backup_exclude_dirs') as $dir) { | ||
| $dir = trim($dir, '/'); | ||
|
|
||
| if ('' === $dir || in_array('..', explode('/', $dir), true) || in_array('.', explode('/', $dir), true)) { | ||
| warning("Skipping invalid backup_exclude_dirs entry: \"$dir\""); | ||
| continue; | ||
| } | ||
|
|
||
| if (!test("[ -d '{{ release_path }}/$dir' ]")) { | ||
| continue; | ||
| } | ||
|
|
||
| run("echo '" . CACHEDIR_TAG_SIGNATURE . "' > '{{ release_path }}/$dir/CACHEDIR.TAG'"); | ||
| debug("Tagged {{ release_path }}/$dir as excluded from backups (CACHEDIR.TAG)"); | ||
| } | ||
| }) | ||
| ->desc('Tag regenerable cache directories to exclude them from hosting backups') | ||
| ; | ||
|
|
||
| before('deploy:symlink', 'backup:exclude_cache'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Backup exclusion | ||
|
|
||
| Excludes regenerable, release-local directories (composer/npm build artifacts, framework caches) from hosting backups by tagging them with a `CACHEDIR.TAG` file, following the [Cache Directory Tagging Specification](https://bford.info/cachedir/). This is honored by [Mittwald's automatic backups](https://developer.mittwald.de/de/docs/v2/guides/operations/backup-exclude/) and by common backup/archive tools (`rsync`, `borg`, `restic`, ... with `--exclude-caches`). | ||
|
|
||
| ## General | ||
|
|
||
| The `backup:exclude_cache` task runs automatically before `deploy:symlink`, tagging every directory listed in `backup_exclude_dirs` (relative to `{{release_path}}`) that exists in the current release. | ||
|
|
||
| The default settings can be found within the [set.php](../deployer/backup/config/set.php) file. | ||
|
|
||
| ```php | ||
| set('backup_exclude_dirs', [ | ||
| 'vendor', | ||
| 'var/cache', | ||
| ]); | ||
| ``` | ||
|
|
||
| Adjust the list per project, e.g. to add framework-specific temp directories, or set it to `[]` to disable the task entirely. | ||
|
|
||
| ## Caution | ||
|
|
||
| Directories tagged this way are excluded from backups entirely and **cannot be restored**, not even by the hoster. Only list directories whose content is fully regenerated by the deploy process (`composer install`, cache warmup) — never shared or writable directories such as `fileadmin`, `uploads`, or `var/log`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.