mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 21:50:30 +00:00
* feat(storage): add team auto-archive assets policy and background job * fix(storage): address code review feedback on lock safety, starvation, and permissions * docs: update readme and expand archive storage documentation with auto-archive details * feat(storage): log info message on auto-archive job start and finish with archived count * style(storage): stack age threshold and grace period vertically with updated grace period description * fix(storage): only log auto-archive info messages when candidate assets are found to process
251 lines
18 KiB
Plaintext
251 lines
18 KiB
Plaintext
---
|
|
title: Archive Storage
|
|
description: Configure secondary cold storage to offload raw media files while preserving in-browser proxy playback and previews.
|
|
---
|
|
|
|
High-resolution camera footage, RAW image sequences, master audio stems, and large 3D assets quickly consume primary storage. Shumai's **Archive Storage** feature enables creative teams to offload heavy master original files to cost-effective cold storage (such as a local NAS, AWS S3 Glacier, or Google Cloud Storage Coldline) while keeping all proxy media, preview images, waveform files, and metadata in primary storage.
|
|
|
|
Team members can continue to browse, search, scrub, and review archived assets in the web browser without interruption. When the original raw file is needed for mastering or color grading, it can be restored back to primary storage with a single click.
|
|
|
|
---
|
|
|
|
## How It Works
|
|
|
|
1. **Original-Only Archiving**: Only the original raw file is moved to archive storage. Previews, thumbnails, and transcoded proxies (e.g., 180p scrubbing proxies, 1080p streamable MP4s, WebP posters) remain in primary storage.
|
|
2. **Durable Asynchronous Workflows**: Moving and restoring files is handled by background worker tasks on a dedicated queue (`archive_queue`) managed by DBOS. Tasks automatically survive network interruptions, slow S3 transfers, and server restarts.
|
|
3. **Transparent Asset Lifecycle**:
|
|
- When an asset is being archived, its status transitions to `archiving` and settles at `archived`.
|
|
- When an asset is being restored, its status transitions to `restoring` and returns to `processed` once the original file is back in primary storage.
|
|
- Trashed assets that are permanently purged automatically delete their original file from archive storage as well.
|
|
4. **Folder & Version Stack Support**: Archiving a folder or version stack recursively archives all contained file assets. Restoring a folder or version stack restores all archived files inside it.
|
|
|
|
---
|
|
|
|
## Storage Topologies
|
|
|
|
Shumai supports flexible storage configurations where primary storage and archive storage can use different backends or storage providers:
|
|
|
|
| Topology | Main Storage | Archive Storage | Description |
|
|
| :------------------------------------ | :----------- | :-------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| **Local NAS / Directory** | Local or S3 | `local` | Offload files to a mounted network folder (NFS / SMB) or a secondary cold disk array. |
|
|
| **Separate S3 Bucket / Provider** | S3 or Local | `s3` | Stream files to a dedicated archive bucket on AWS S3, Wasabi, Backblaze B2, or Google Cloud Storage. |
|
|
| **Same S3 Bucket (In-Place Tiering)** | AWS S3 | `s3` | Re-tier objects in-place on AWS S3 using cold storage classes (`GLACIER`, `GLACIER_IR`, `DEEP_ARCHIVE`) without re-uploading bytes over the network. |
|
|
|
|
---
|
|
|
|
## Configuration Variables
|
|
|
|
Configure archive storage by adding the following environment variables to your `.env` file or Docker Compose configuration.
|
|
|
|
### General Configuration
|
|
|
|
| Variable | Description | Required | Default |
|
|
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :--------------- |
|
|
| `ARCHIVE_STORAGE_BACKEND` | Storage backend for archives: `local` or `s3`. When unset, archive functionality is disabled in the WebUI. | No | Unset (Disabled) |
|
|
| `CONCURRENCY_ARCHIVE` | Maximum concurrent archive and restore tasks executed by background workers. | No | `5` |
|
|
| `SHUMAI_WORKERS` | Worker queues listened to by the application server: `all` (default), `none`, `agent` (or `ai`), `transcode`, `archive`. Set to `all` or `archive` to process tasks. | No | `all` |
|
|
| `AUTO_ARCHIVE_INTERVAL_MINUTES` | Frequency (in minutes) of the background auto-archive scanner job. Accepts decimal numbers (e.g. `0.02` for testing). | No | `60` (1 hour) |
|
|
|
|
### Local Archive Storage
|
|
|
|
Used when `ARCHIVE_STORAGE_BACKEND=local`:
|
|
|
|
| Variable | Description | Required | Default |
|
|
| :------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :--------------- |
|
|
| `ARCHIVE_LOCAL_ROOT` | Host filesystem directory path where archived files are stored. Must not overlap with main local storage directory (`./data` or `./data/<S3_BUCKET>`). | Yes | Unset (Required) |
|
|
|
|
### S3 Archive Storage
|
|
|
|
Used when `ARCHIVE_STORAGE_BACKEND=s3`. Note that archive storage maintains its own configuration and **never falls back** to the primary `S3_*` environment variables:
|
|
|
|
| Variable | Description | Required | Default |
|
|
| :--------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :------------------------------------ |
|
|
| `ARCHIVE_S3_BUCKET` | Destination S3 bucket for archived files (can be a dedicated bucket or the same bucket as `S3_BUCKET` for in-place tiering). | Yes | Unset (Required) |
|
|
| `ARCHIVE_S3_ACCESS_KEY_ID` | Access key ID for the archive S3 service. | Yes | Unset (Required) |
|
|
| `ARCHIVE_S3_SECRET_ACCESS_KEY` | Secret access key for the archive S3 service. | Yes | Unset (Required) |
|
|
| `ARCHIVE_AWS_ENDPOINT_URL_S3` | S3 endpoint URL for archive storage (e.g. MinIO, Cloudflare R2, Google Cloud Storage). | No | Unset (AWS standard endpoint) |
|
|
| `ARCHIVE_S3_REGION` | S3 region for the archive bucket. | No | `auto` |
|
|
| `ARCHIVE_S3_FORCE_PATH_STYLE` | Use path-style S3 URLs (`true` for MinIO/path-style, `false` for virtual-hosted style). | No | `true` |
|
|
| `ARCHIVE_S3_STORAGE_CLASS` | S3 storage class to apply to archived objects (e.g. `GLACIER`, `GLACIER_IR`, `DEEP_ARCHIVE`, `COLDLINE`). Required and must not be `STANDARD` when archiving to the same S3 bucket. | No | Unset |
|
|
| `ARCHIVE_S3_USE_RESTORE_OBJECT` | Controls whether S3 `RestoreObject` is called before reading archived objects (`auto`, `true`, or `false`). | No | `auto` |
|
|
| `ARCHIVE_S3_RESTORE_DAYS` | Number of days a restored temporary copy remains readable in S3 for asynchronous Glacier restores. | No | `1` |
|
|
| `ARCHIVE_S3_RESTORE_TIER` | S3 Glacier retrieval tier (`Expedited`, `Standard`, or `Bulk`). Omit when using providers that do not require asynchronous retrieval. | No | Unset |
|
|
| `ARCHIVE_RESTORE_POLL_INTERVAL_MS` | Milliseconds between status checks while waiting for an asynchronous cold storage restore. | No | `60000` (1 min initial, 5 min steady) |
|
|
|
|
---
|
|
|
|
## Configuration Examples
|
|
|
|
### 1. Local NAS / Mounted Path
|
|
|
|
Ideal for self-hosted teams with on-premises Network Attached Storage (Synology, QNAP, TrueNAS, or an NFS/SMB share mounted to the host machine):
|
|
|
|
```env
|
|
# Main storage on local disk or S3
|
|
STORAGE_BACKEND=local
|
|
LOCAL_STORAGE_PATH=./storage
|
|
|
|
# Archive storage pointing to your mounted NAS directory
|
|
ARCHIVE_STORAGE_BACKEND=local
|
|
ARCHIVE_LOCAL_ROOT=/mnt/nas/shumai-archive
|
|
```
|
|
|
|
In `docker-compose.yaml`, mount the host NAS volume into the container:
|
|
|
|
```yaml
|
|
services:
|
|
shumai:
|
|
volumes:
|
|
- /mnt/nas/shumai-archive:/mnt/nas/shumai-archive
|
|
environment:
|
|
ARCHIVE_STORAGE_BACKEND: local
|
|
ARCHIVE_LOCAL_ROOT: /mnt/nas/shumai-archive
|
|
```
|
|
|
|
---
|
|
|
|
### 2. AWS S3 Glacier Instant Retrieval (Archive)
|
|
|
|
AWS S3 Glacier Instant Retrieval (`GLACIER_IR`) offers cold storage pricing with **millisecond retrieval latency**. Because objects in `GLACIER_IR` do not require an asynchronous `RestoreObject` request, restoring an asset to main storage is instantaneous.
|
|
|
|
#### Same-Bucket In-Place Tiering (Fast Path)
|
|
|
|
If your main storage is AWS S3, you can tier files into `GLACIER_IR` within the **same bucket** without re-uploading bytes over the network:
|
|
|
|
```env
|
|
# Main Storage
|
|
STORAGE_BACKEND=s3
|
|
S3_BUCKET=my-shumai-production
|
|
S3_REGION=us-east-1
|
|
S3_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
AWS_ENDPOINT_URL_S3=https://s3.us-east-1.amazonaws.com
|
|
|
|
# Archive Storage (same bucket & credentials with cold storage class)
|
|
ARCHIVE_STORAGE_BACKEND=s3
|
|
ARCHIVE_S3_BUCKET=my-shumai-production
|
|
ARCHIVE_S3_REGION=us-east-1
|
|
ARCHIVE_S3_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
ARCHIVE_S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
ARCHIVE_AWS_ENDPOINT_URL_S3=https://s3.us-east-1.amazonaws.com
|
|
ARCHIVE_S3_STORAGE_CLASS=GLACIER_IR
|
|
```
|
|
|
|
#### Dedicated Archive Bucket
|
|
|
|
If you prefer keeping archived media in a separate S3 bucket:
|
|
|
|
```env
|
|
# Archive Storage in a separate bucket
|
|
ARCHIVE_STORAGE_BACKEND=s3
|
|
ARCHIVE_S3_BUCKET=my-shumai-archive-glacier-ir
|
|
ARCHIVE_S3_REGION=us-east-1
|
|
ARCHIVE_S3_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
ARCHIVE_S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
ARCHIVE_AWS_ENDPOINT_URL_S3=https://s3.us-east-1.amazonaws.com
|
|
ARCHIVE_S3_STORAGE_CLASS=GLACIER_IR
|
|
```
|
|
|
|
---
|
|
|
|
### 3. AWS S3 Glacier Flexible Archive (Cold Storage)
|
|
|
|
For maximum cost savings on rarely accessed footage, AWS S3 Flexible Archive (`GLACIER`) or Deep Archive (`DEEP_ARCHIVE`) stores data at the lowest storage rates.
|
|
|
|
When a user restores an asset from Glacier, Shumai initiates a `RestoreObject` request, puts the background workflow into durable DBOS sleep, and periodically checks until AWS completes the retrieval:
|
|
|
|
```env
|
|
ARCHIVE_STORAGE_BACKEND=s3
|
|
ARCHIVE_S3_BUCKET=my-shumai-cold-archive
|
|
ARCHIVE_S3_REGION=us-east-1
|
|
ARCHIVE_S3_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
ARCHIVE_S3_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
ARCHIVE_AWS_ENDPOINT_URL_S3=https://s3.us-east-1.amazonaws.com
|
|
ARCHIVE_S3_STORAGE_CLASS=GLACIER
|
|
|
|
# Keep the restored temporary copy accessible for 7 days
|
|
ARCHIVE_S3_RESTORE_DAYS=7
|
|
|
|
# Glacier retrieval tier: Standard (3-5 hours), Expedited (1-5 min), or Bulk (5-12 hours)
|
|
ARCHIVE_S3_RESTORE_TIER=Standard
|
|
```
|
|
|
|
> [!NOTE]
|
|
> During a Glacier restore, DBOS schedules durable sleep timers in PostgreSQL. The worker thread is completely freed and does not consume concurrency slots while waiting for AWS to thaw the file.
|
|
|
|
---
|
|
|
|
### 4. Google Cloud Storage Coldline (Archive)
|
|
|
|
Google Cloud Storage (GCS) provides S3-compatible XML APIs and low-cost storage classes such as `COLDLINE` and `ARCHIVE`. Like Glacier Instant Retrieval, GCS Coldline provides **immediate access** without requiring an asynchronous thaw step:
|
|
|
|
```env
|
|
# Main storage (e.g. Cloudflare R2, MinIO, or standard GCS)
|
|
STORAGE_BACKEND=s3
|
|
S3_BUCKET=shumai-main
|
|
...
|
|
|
|
# Archive storage on GCS Coldline
|
|
ARCHIVE_STORAGE_BACKEND=s3
|
|
ARCHIVE_S3_BUCKET=shumai-coldline-archive
|
|
ARCHIVE_S3_ACCESS_KEY_ID=GOOG1EXAMPLETOCKENKEY
|
|
ARCHIVE_S3_SECRET_ACCESS_KEY=your-gcs-hmac-secret-access-key
|
|
ARCHIVE_AWS_ENDPOINT_URL_S3=https://storage.googleapis.com
|
|
ARCHIVE_S3_STORAGE_CLASS=COLDLINE
|
|
```
|
|
|
|
> [!TIP]
|
|
> Google Cloud Storage objects are readable immediately and do not accept AWS Glacier retrieval parameters. Do not set `ARCHIVE_S3_RESTORE_TIER`. If using GCS's `ARCHIVE` storage class, set `ARCHIVE_S3_USE_RESTORE_OBJECT=false` to bypass S3 `RestoreObject` calls.
|
|
|
|
---
|
|
|
|
## Automatic Asset Archival
|
|
|
|
In addition to manual on-demand archival, Shumai allows teams to automate cold storage tiering based on asset age lifecycle policies. This ensures heavy original master files are automatically offloaded to secondary cold storage without requiring manual housekeeping from creative staff or administrators.
|
|
|
|
### WebUI Configuration
|
|
|
|
Team owners can configure automatic archival under **Team Settings > Storage**:
|
|
|
|
1. **Archive Storage Status Overview**:
|
|
- Displays the current system archive storage backend (`local` or `s3`), endpoint, bucket, or root directory configured on the server.
|
|
- If archive storage is not configured in server environment variables, a warning alert is displayed, and auto-archive controls are disabled.
|
|
- For security, credentials and private server settings are not exposed to client browsers.
|
|
|
|
2. **Automatic Asset Archival Policy**:
|
|
- **Enable Auto Archive**: Toggle automated background archival on or off for the team (disabled by default; requires an active archive storage backend).
|
|
- **Archive Criteria (`method`)**:
|
|
- **Not modified for specified days (`not_updated`)**: Evaluates the last modification timestamp (`updatedAt`). Ideal for active production workflows—files stay in fast primary storage as long as team members are actively commenting, annotating, or modifying them. Once no modifications have occurred for the configured duration, the asset is moved to cold storage.
|
|
- **After creation for specified days (`after_created`)**: Evaluates the initial upload/creation timestamp (`createdAt`). Ideal for strict retention or compliance pipelines where footage is tiered based on its age (e.g., 60 or 90 days after delivery) regardless of recent review comments.
|
|
- **Age Threshold (`days`)**: The threshold in days (between 1 and 3,650 days) after which eligible assets are queued for archival.
|
|
- **Post-Restore Grace Period (`postRestoreGraceDays`)**:
|
|
- When an asset is restored from archive back to primary storage, its modification date is refreshed to the restore time.
|
|
- When using the **After creation** rule, an asset older than the threshold (e.g. 100 days old) would otherwise be immediately picked up and re-archived by the very next hourly scan.
|
|
- The post-restore grace period (default: 30 days) guarantees that restored files remain in primary storage for at least the specified number of days before becoming eligible for automated archival again. This value should be set smaller than the Age Threshold. Under this policy, only files that are older than the Age Threshold and have also surpassed the Post-Restore Grace Period since restoration are auto-archived.
|
|
|
|
### Sibling Deduplication & Safety
|
|
|
|
Shumai uses content-addressable storage keys (`storage_keys`) to deduplicate identical files across projects and folders:
|
|
|
|
- **Sibling Protection**: If multiple asset records reference the same underlying storage object (e.g., copied or duplicated files across folders or projects), the auto-archive scanner inspects all sibling assets.
|
|
- **Strict Consensus**: The underlying storage file is **only** archived if **all active sibling files** satisfy the team's auto-archive criteria and are in a stable `processed` state.
|
|
- **Starvation-Free Scheduling**: If any sibling copy was modified recently or is currently in an active workflow, the storage key is safely skipped without blocking other eligible assets from being archived.
|
|
|
|
### Background Scanner & Execution Semantics
|
|
|
|
The auto-archive job runs periodically in the background:
|
|
|
|
- **Scan Frequency**: Configured via the `AUTO_ARCHIVE_INTERVAL_MINUTES` environment variable (defaults to `60` minutes; accepts decimal values such as `0.02` for automated testing).
|
|
- **Distributed Leader Election**: Uses PostgreSQL transaction-scoped advisory locks (`pg_try_advisory_xact_lock`) during the candidate discovery phase. In multi-pod or multi-replica container deployments, only one server instance performs the scan per interval while other replicas cleanly skip.
|
|
- **Race Condition Prevention**: During archival, candidate assets transition atomically via conditional SQL (`UPDATE assets SET status = 'archiving' WHERE status = 'processed'`) protected by row-level `storage_keys FOR UPDATE` locks. This guarantees zero race conditions with concurrent manual user archival, restoration, or file deletion.
|
|
|
|
---
|
|
|
|
## WebUI Behavior & Permissions
|
|
|
|
- **Permissions**: Only team **Owners** and **Editors** can archive or restore assets.
|
|
- **Context Menus**: Right-click any file, folder, or version stack in the file browser to select **Archive** or **Restore from Archive**.
|
|
- **Visual Badges**: Archived items display an `Archived` badge on grid cards and list rows. Inside the file viewer, an archive icon is displayed in front of the file name in the breadcrumb bar.
|
|
- **Playback & Previews**: Video streaming, scrubbers, waveform audio, PDF rendering, and image viewing remain fully functional using cached proxies.
|
|
- **Download Restrictions**: The download button for the original raw file is disabled with a tooltip explaining that the raw file is archived. Transcoded proxy downloads (e.g. 1080p MP4) remain available.
|