storyblok-restore
v1.0.3
Published
npx CLI tool for restoring full Storyblok spaces from backup files
Downloads
127
Readme
Storyblok Restore
A powerful CLI tool to restore entire Storyblok CMS spaces from backup files created by storyblok-backup.
This tool handles the complete restoration process including dependency resolution, ID/UUID mapping, reference fixing, and intelligent conflict resolution across all Storyblok resource types.
Features
- 🔄 Complete Space Restoration - Restore entire Storyblok spaces from backup folders
- 🎯 Selective Resource Restoration - Choose specific resource types to restore
- 🔗 Dependency Resolution - Automatically handles resource dependencies and restoration order
- 🆔 ID/UUID Mapping - Manages cross-resource references and ID mappings
- ⚡ Smart Conflict Resolution - Intelligent upsert logic (create-first, update-on-conflict)
- 📁 Asset File Support - Restores both asset metadata and actual files
- 🔍 Verbose Logging - Detailed progress tracking and debugging information
Prerequisites
- Node.js (v16 or higher)
- A Storyblok account with Management API access
- OAuth token from your Storyblok account settings
- Backup files created by storyblok-backup
Installation
Global Installation (Recommended)
npm install -g storyblok-restoreLocal Installation
npm install storyblok-restoreUsing npx (No Installation Required)
npx storyblok-restoreUsage
Basic Space Restore
storyblok-restore space-restore \
--backup-path ./backup \
--token YOUR_OAUTH_TOKEN \
--space YOUR_SPACE_IDEnvironment Variables
You can set credentials via environment variables:
export STORYBLOK_OAUTH_TOKEN="your_oauth_token"
export STORYBLOK_SPACE_ID="your_space_id"
export STORYBLOK_REGION="eu" # Optional: eu, us, ap, ca, cn
storyblok-restore space-restore --backup-path ./backupCommand Options
| Option | Description | Required |
|--------|-------------|----------|
| --backup-path | Path to the backup folder | ✅ |
| --token | Storyblok OAuth token | ✅* |
| --space | Storyblok space ID | ✅* |
| --region | Region (eu, us, ap, ca, cn) | ❌ |
| --resource-types | Comma-separated list of resource types | ❌ |
| --verbose | Enable detailed logging | ❌ |
*Required unless set via environment variables
Examples
Complete Space Restoration
# Restore all resources from backup
storyblok-restore space-restore \
--backup-path ./my-backup \
--token $STORYBLOK_OAUTH_TOKEN \
--space $STORYBLOK_SPACE_ID \
--verboseSelective Resource Restoration
# Restore only specific resource types
storyblok-restore space-restore \
--backup-path ./my-backup \
--token $STORYBLOK_OAUTH_TOKEN \
--space $STORYBLOK_SPACE_ID \
--resource-types "stories,components,assets"Multi-Region Restoration
# Restore to US region space
storyblok-restore space-restore \
--backup-path ./my-backup \
--token $STORYBLOK_OAUTH_TOKEN \
--space $STORYBLOK_SPACE_ID \
--region usSupported Resource Types
The tool can restore the following Storyblok resource types:
webhooks- Webhook configurations (secrets must be manually re-added)access-tokens- API access tokenscollaborators- Space collaborators and permissionscomponent-groups- Component organization groupscomponents- Reusable content componentsdatasources- External data sourcesdatasource-entries- Data source entries and contentasset-folders- Asset organization foldersassets- Media assets and filesstories- Content pages and entries
Expected Backup Structure
The tool expects backup folders created by storyblok-backup with this structure:
backup/
├── space-{space_id}.json # Space configuration
├── webhooks/ # Webhook configurations
│ └── *.json
├── access-tokens/ # API access tokens
│ └── *.json
├── collaborators/ # Space collaborators
│ └── *.json
├── component-groups/ # Component groups
│ └── *.json
├── components/ # Content components
│ └── *.json
├── datasources/ # Data sources
│ └── *.json
├── datasource-entries/ # Data source entries
│ └── *.json
├── asset-folders/ # Asset folders
│ └── *.json
├── assets/ # Asset metadata
│ └── *.json
├── asset-files/ # Actual asset files
│ └── *.*
└── stories/ # Content stories
└── *.jsonHow It Works
- Backup Analysis - Scans the backup folder structure and validates resources
- Dependency Resolution - Determines the correct restoration order based on resource dependencies
- Smart Restoration - Uses intelligent upsert logic:
- Attempts to create new resources (fast path for 99.9% of cases)
- Detects conflicts and automatically switches to update mode
- Finds existing resources and updates them with new data
- Reference Fixing - Updates cross-resource references and ID mappings
- Asset Handling - Uploads asset files and links them to asset metadata
- Progress Tracking - Provides detailed logging and error reporting
Configuration
Using .env File
Create a .env file in your project root:
STORYBLOK_OAUTH_TOKEN=your_oauth_token_here
STORYBLOK_SPACE_ID=123456
STORYBLOK_REGION=euTroubleshooting
Getting Help
- Use the
--verboseflag for detailed logging - Check that your backup structure matches the expected format
- Ensure all required dependencies are included in the backup
Acknowledgments
This tool is designed to work with backups created by storyblok-backup by @webflorist. Special thanks for creating the comprehensive backup solution that makes this restoration tool possible.
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for development setup and guidelines.
