Storage and backups
Pratique removes files that nothing refers to every day. You can add a cleanup policy to remove cached packages that can be fetched again, and you back up the database and stored files with one command.
What Pratique stores
In artifactory mode, the default, Pratique keeps a copy of every file it delivers. The data directory
(PRATIQUE_DATA, /data in the Docker image) holds two things:
pratique.db, the SQLite database. It holds the audit log, the hash of every file, tokens (as hashes), settings, incidents, projects and build records.blobs/, the package files. This is also the only copy of your private packages.
With PRATIQUE_DATABASE_URL and PRATIQUE_S3_BUCKET set, the database is in Postgres and the
package files are in S3. Each replica still uses PRATIQUE_DATA for temporary files.
Automatic removal of unreferenced files
Once a day, Pratique deletes stored files that no record refers to. It also deletes temporary files that rejected uploads and interrupted requests leave behind. A file must be older than one hour before it is deleted, so a file that is still being recorded is safe.
This removal never touches a cached package that still has a record. Only a cleanup policy can mark those for
removal. To run the same removal now, use pratique gc with the same settings as the server:
pratique --config pratique.yaml gc
# Removed 12 unreferenced files
Cleanup policy
The Storage page shows how much is stored and adds a policy for files that are still referenced. The policy is off until you turn it on. Only admins can change it.
The policy removes a stored copy, not the record of the file. See removal does not forget.
| Setting | On the Storage page | What it does | Default |
|---|---|---|---|
enabled | Run this every day | Runs the policy once a day. When it is off, nothing is removed unless you run it yourself. | off |
undelivered_days | Files no client ever received | Removes files that no client received after this many days in storage, such as a release fetched only to compare it. 0 skips this. | 30 |
unused_days | Files nobody has downloaded lately | Removes files whose last download is older than this many days. 0 skips this. | 90 |
keep_newest | Always keep | Keeps this many of the newest versions of each package, however long since their last download. It does not protect a file that no client ever received. | 3 |
max_gb | Size limit | When storage is over this size, removes the least recently used files first, apart from the newest versions kept above. 0 means no limit. | 0 |
build_days | Build records | Forgets build records older than this many days. 0 keeps them all. | 0 |
Day values go from 0 to 3650, and Always keep goes from 0 to 1000.
Preview, run once or run daily
Preview the settings
Change the numbers and select Preview these settings. The page lists what those settings would remove, with the reason for each file, the largest first. Nothing is saved or removed.
Save the policy
Select Save policy. Select Run this every day first if you want the daily run. The change is recorded in the audit log.
Run it once
Under What the saved policy would remove, select Remove these now. This applies the saved policy one time, also when the daily run is off.
Each run that removes something writes one event to the audit log, with the number of files, their total size and the number of build records it forgot.
Set the policy in the config file
You can set the same policy in pratique.yaml. The Storage page then shows it as
In code and you cannot change it there.
storage_cleanup:
enabled: true
undelivered_days: 30 # files no client ever received
unused_days: 90 # files nobody has downloaded for this long
keep_newest: 3 # the newest versions of each package stay anyway
max_gb: 500 # past this, the least recently used go first
build_days: 365 # forget older build records
What is never removed
- Private packages, because no other copy exists.
- Composer archives with no published hash, because they cannot always be fetched again with the same bytes.
- Versions that a project's lockfile lists, or that a build from the last 90 days used, because upstream could remove them.
The Storage page shows how many files are in each group.
Removal does not forget
When the policy removes a file, its record stays, with the hash Pratique saw first. When a client asks for the file again, the usual policy checks run. If the file is cleared, Pratique fetches it again, and the new copy must be identical to the first one.
If the file comes back different, Pratique refuses it with the reason "this file was removed from storage, and came back different from the one first seen", and opens an incident: A published file changed upstream.
If a registry deletes a file after you removed your copy, the file is gone. To protect a version that you depend on,
report the project's lockfiles with pratique inventory. See CLI reference.
In firewall mode
In firewall mode, Pratique keeps no package files. Each cleared file is deleted within about 20 minutes, and the Storage page is not shown. A saved or file-based policy still forgets old build records.
Back up and restore
SQLite and local disk
pratique backup DIR copies the database and the package files to DIR. It is safe to run
while the server runs: the database copy is consistent, and package files never change after they are stored. Later
runs into the same directory copy only the new package files.
PRATIQUE_DATA=/data pratique backup /backups/pratique
# Backed up the database and 214 new files to /backups/pratique
In the Docker image, the binary is /pratique and PRATIQUE_DATA is already
/data:
docker compose exec -T pratique /pratique backup /data/backup
pratique backup reads PRATIQUE_DATA and PRATIQUE_DATABASE_URL from the
environment. It does not read pratique.yaml. If you set data_dir only in the file, set
PRATIQUE_DATA for the backup command too.
Run the backup on a schedule, and copy the backup directory off the machine. To restore:
Stop the server
Stop Pratique, so nothing writes to the data directory.
Restore the backup
Run
PRATIQUE_DATA=/data pratique restore /backups/pratique. It checks the backup's database first and copies it and the package files into the data directory. If the data directory already has a database, add--force; the current database is kept aspratique.db.before-restore-and the time.Start the server
Start Pratique again. Then check
/readyzand open the Incidents page.
Test a restore on a schedule too. A backup that you never restored is not proven.
Postgres and S3
pratique backup refuses to run when PRATIQUE_DATABASE_URL is set, so a backup cannot
silently miss your data. Use your provider's tools instead:
- The database:
pg_dump, or your provider's snapshots. - The bucket: versioning or replication.
What to keep out of backups
Keep PRATIQUE_AUDIT_KEY out of the database backup and out of the same storage. Someone who has the
database and the key can forge a signed audit log. Store the key in a password manager or secret store, and store
the public key in a different place. See audit log.
The database holds your audit log, which contains email addresses and IP addresses. Protect the backup like the server.