Skip to content

Commit 78f1a29

Browse files
committed
update readme
1 parent 86d8659 commit 78f1a29

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

scripts/README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Redis to Local Storage Migration Scripts
2+
3+
This directory contains scripts to migrate data from a Redis dump file to the local JSON storage format.
4+
5+
## Scripts
6+
7+
### `migrate_redis_to_local.sh` (Main Script)
8+
The master script that orchestrates the entire migration process.
9+
10+
**Usage:**
11+
```bash
12+
./scripts/migrate_redis_to_local.sh
13+
```
14+
15+
**What it does:**
16+
1. Starts Redis with your dump file (`/Users/xuhuizhou/Downloads/dump_1.rdb`)
17+
2. Exports all data to `~/.sotopia/data/` in local JSON format
18+
3. Optionally stops Redis when done
19+
20+
### `start_redis_with_dump.sh`
21+
Starts a Redis server with the dump file loaded.
22+
23+
**Usage:**
24+
```bash
25+
./scripts/start_redis_with_dump.sh
26+
```
27+
28+
**Features:**
29+
- Automatically detects and stops existing Redis instances on port 6379
30+
- Uses `redis-stack-server` if available (required for dump files with Redis modules)
31+
- Falls back to `redis-server` if redis-stack is not found
32+
- Creates temporary directory for Redis data
33+
- Waits for Redis to be ready before exiting
34+
35+
### `export_redis_to_local.py`
36+
Python script to export all models from Redis to local JSON storage.
37+
38+
**Usage:**
39+
```bash
40+
# Basic usage (connects to redis://localhost:6379)
41+
uv run python scripts/export_redis_to_local.py
42+
43+
# With custom Redis URL
44+
uv run python scripts/export_redis_to_local.py --redis-url redis://localhost:6380
45+
46+
# With custom output directory
47+
uv run python scripts/export_redis_to_local.py --output-dir /path/to/output
48+
49+
# Quiet mode (no progress bars)
50+
uv run python scripts/export_redis_to_local.py --quiet
51+
```
52+
53+
**Exported Models:**
54+
- AgentProfile
55+
- EnvironmentProfile
56+
- RelationshipProfile
57+
- EnvAgentComboStorage
58+
- EnvironmentList
59+
- Annotator
60+
- EpisodeLog
61+
- AnnotationForEpisode
62+
- NonStreamingSimulationStatus
63+
64+
### `stop_redis.sh`
65+
Stops the Redis server started by `start_redis_with_dump.sh`.
66+
67+
**Usage:**
68+
```bash
69+
./scripts/stop_redis.sh
70+
```
71+
72+
## Output Format
73+
74+
Data is exported to `~/.sotopia/data/` with the following structure:
75+
76+
```
77+
~/.sotopia/data/
78+
├── AgentProfile/
79+
│ ├── {uuid1}.json
80+
│ ├── {uuid2}.json
81+
│ └── ...
82+
├── EnvironmentProfile/
83+
│ ├── {uuid1}.json
84+
│ └── ...
85+
├── EnvAgentComboStorage/
86+
│ ├── {uuid1}.json
87+
│ └── ...
88+
├── Annotator/
89+
│ ├── {uuid1}.json
90+
│ └── ...
91+
└── ...
92+
```
93+
94+
Each JSON file contains a single model instance with 2-space indentation:
95+
96+
```json
97+
{
98+
"pk": "01H7VJPFPQ67TTMWZ9246SQ2A4",
99+
"env_id": "01H7VFHPJKR16MD1KC71V4ZRCF",
100+
"agent_ids": [
101+
"01H5TNE5PMBJ9VHH51YC0BB64C",
102+
"01H5TNE5P6KZKR2AEY6SZB83H0"
103+
]
104+
}
105+
```
106+
107+
## Using the Exported Data
108+
109+
After running the migration, you can use the local storage backend by setting the environment variable:
110+
111+
```bash
112+
export SOTOPIA_STORAGE_BACKEND=local
113+
```
114+
115+
Then all Sotopia database operations will use the local JSON files instead of Redis:
116+
117+
```python
118+
from sotopia.database import AgentProfile, Annotator
119+
120+
# Automatically uses local storage when SOTOPIA_STORAGE_BACKEND=local
121+
annotators = Annotator.all()
122+
for annotator in annotators:
123+
print(f"{annotator.name}: {annotator.email}")
124+
```
125+
126+
## Requirements
127+
128+
- Redis 8.0+ or redis-stack-server (for loading dump files with Redis modules)
129+
- Python 3.10+
130+
- uv package manager
131+
- Sotopia dependencies installed (`uv sync --all-extras`)
132+
133+
## Troubleshooting
134+
135+
### "Can't handle RDB format version X"
136+
Your Redis version is too old. Upgrade to Redis 8.0+:
137+
```bash
138+
brew upgrade redis
139+
```
140+
141+
### "The RDB file contains AUX module data I can't load"
142+
The dump file was created with redis-stack-server (includes RediSearch, RedisJSON, etc.). Install redis-stack:
143+
```bash
144+
brew install redis-stack
145+
```
146+
147+
### "Redis URL must specify one of the following schemes"
148+
Make sure the `REDIS_OM_URL` environment variable is set correctly:
149+
```bash
150+
export REDIS_OM_URL="redis://localhost:6379"
151+
```
152+
153+
## Migration Results
154+
155+
After successful migration, you should see output like:
156+
157+
```
158+
Export Summary
159+
============================================================
160+
✓ Annotator: 3 records exported (0 errors)
161+
✓ EnvAgentComboStorage: 450 records exported (0 errors)
162+
✓ AnnotationForEpisode: 439 records exported (0 errors)
163+
============================================================
164+
Total: 892 records exported (0 errors)
165+
```

0 commit comments

Comments
 (0)