Skip to content

Commit 59207a6

Browse files
authored
Merge pull request #3144 from OpenC3/backups
Create backups docs
2 parents 7ed4559 + 911f182 commit 59207a6

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
title: Backups
3+
description: How to backup and restore COSMOS
4+
sidebar_custom_props:
5+
myEmoji: 🛟
6+
---
7+
8+
## COSMOS 7
9+
10+
COSMOS 7 stores data in two places: the S3-compatible bucket storage (versitygw) and the Time Series Database (QuestDB). Both must be backed up for a complete recovery.
11+
12+
### Bucket Storage (S3)
13+
14+
#### Kubernetes / AWS with S3
15+
16+
If you are running COSMOS in Kubernetes or on an AWS EC2 with S3 as your bucket backend, S3 already handles durability and redundancy. No additional backup steps are required for bucket data.
17+
18+
#### Standalone Server
19+
20+
On a standalone server, versitygw uses a standard POSIX filesystem backend. The data is stored in the `openc3-object-v` Docker volume mounted at `/data` inside the `openc3-buckets` container. Since it's a regular filesystem, you can copy the files directly without needing the MinIO Client.
21+
22+
To back up, use a temporary Docker container to mount both the COSMOS volume and your backup destination:
23+
24+
```bash
25+
# Back up bucket data to a shared network drive or external path
26+
docker run --rm \
27+
-v openc3-object-v:/data:ro \
28+
-v /mnt/backup:/backup eeacms/rsync \
29+
rsync -a /data/ /backup/buckets/
30+
```
31+
32+
Replace `/mnt/backup` with your shared network drive or backup destination. This mounts the `openc3-object-v` volume as read-only and copies its contents to the backup location. This command is safe to run on a schedule for incremental backups since `rsync` only copies changed files.
33+
34+
### QuestDB
35+
36+
QuestDB requires a checkpoint-based backup procedure. See the [QuestDB backup documentation](https://questdb.com/docs/operations/backup/#questdb-oss-manual-backups-with-checkpoints) for full details.
37+
38+
The QuestDB data is stored in the `openc3-tsdb-v` Docker volume mounted at `/var/lib/questdb` inside the `openc3-tsdb` container.
39+
40+
#### Backup Procedure
41+
42+
1. **Create a checkpoint** to pause housekeeping while keeping the database available for reads and writes.
43+
44+
**From the COSMOS Admin Console:** Open the Admin Console and the TSDB tab. Run the following:
45+
46+
```sql
47+
CHECKPOINT CREATE
48+
```
49+
50+
**From the command line:** Execute the SQL directly against the QuestDB container's HTTP API:
51+
52+
```bash
53+
docker exec openc3-tsdb-1 \
54+
curl -sS -u "$OPENC3_TSDB_USERNAME:$OPENC3_TSDB_PASSWORD" \
55+
'http://localhost:9000/exec?query=CHECKPOINT+CREATE'
56+
```
57+
58+
2. **Copy the QuestDB data directory.** While the checkpoint is active, copy the entire volume contents (including `db`, `snapshot`, and all subdirectories) to your backup destination.
59+
60+
**Kubernetes / AWS:** Copy to an S3 bucket. Replace openc3-tsdb-1 with the real container name. Replace XXXXX and YYYYY with actual keys:
61+
62+
```bash
63+
# Example using a temporary pod or container with aws cli
64+
docker run --rm --volumes-from openc3-tsdb-1 \
65+
-e AWS_ACCESS_KEY_ID=XXXXX -e AWS_SECRET_ACCESS_KEY=YYYYY \
66+
amazon/aws-cli s3 sync /var/lib/questdb/ s3://your-backup-bucket/questdb/
67+
```
68+
69+
**Standalone server:** Copy to a local directory. Replace openc3-tsdb-1 with the real container name. Using rsync allows for incremental backups:
70+
71+
```bash
72+
# Example using eeacms/rsync container
73+
docker run --rm --volumes-from openc3-tsdb-1 \
74+
-v $(pwd):/backup eeacms/rsync \
75+
rsync -a /var/lib/questdb/ /backup/questdb/
76+
```
77+
78+
3. **Release the checkpoint** to resume normal operations:
79+
80+
**From the COSMOS Admin Console:**
81+
82+
```sql
83+
CHECKPOINT RELEASE
84+
SELECT * FROM checkpoint_status()
85+
```
86+
87+
**From the command line:**
88+
89+
```bash
90+
docker exec openc3-tsdb-1 \
91+
curl -sS -u "$OPENC3_TSDB_USERNAME:$OPENC3_TSDB_PASSWORD" \
92+
'http://localhost:9000/exec?query=CHECKPOINT+RELEASE'
93+
```
94+
95+
#### Restore Procedure
96+
97+
1. **Stop COSMOS**
98+
99+
```bash
100+
openc3.sh stop
101+
```
102+
103+
2. **Restore the QuestDB volume contents from your backup.** Replace openc3-tsdb-v with the real volume name:
104+
105+
```bash
106+
docker run --rm -v openc3-tsdb-v:/var/lib/questdb \
107+
-v $(pwd):/backup alpine \
108+
sh -c "rm -rf /var/lib/questdb/* && cp -a /backup/questdb/. /var/lib/questdb/"
109+
```
110+
111+
3. **Create a trigger file to initiate the restore:**
112+
113+
```bash
114+
docker run --rm \
115+
-v openc3-tsdb-v:/var/lib/questdb alpine \
116+
touch /var/lib/questdb/_restore
117+
```
118+
119+
4. **Run COSMOS** -- QuestDB will automatically perform the restore procedure and remove the `_restore` file on success
120+
121+
```bash
122+
openc3.sh run
123+
# Monitor the TSDB docker logs to watch progress
124+
docker logs -f openc3-tsdb-1
125+
```
126+
127+
:::info Version Compatibility
128+
QuestDB backups are compatible across patch versions within the same major version (e.g., 9.0.0 and 9.1.0 are compatible).
129+
:::
130+
131+
## COSMOS 6
132+
133+
The primary data to backup in COSMOS 6 is the bucket storage in MINIO.
134+
135+
### Kubernetes / AWS with S3
136+
137+
If you are running COSMOS in Kubernetes or on AWS with S3 as your bucket backend, S3 already handles durability and redundancy. No additional backup steps are required.
138+
139+
### Standalone Server
140+
141+
On a standalone server, MINIO uses an internal object format that requires the [MinIO Client (`mc`)](https://min.io/docs/minio/linux/reference/minio-mc.html) to access. Use `mc` to copy files to a backup location such as a shared network drive.
142+
143+
#### Backup Procedure
144+
145+
1. **Copy the MINIO /data directory.** Replace openc3-minio-1 with the actual container name:
146+
147+
```bash
148+
docker run --rm --volumes-from openc3-minio-1 \
149+
-v $(pwd):/backup openc3inc/openc3-init \
150+
mc mirror --preserve /data /backup/minio
151+
```
152+
153+
The `mc mirror --preserve` command is idempotent and only copies new or changed files, making it safe to run on a schedule for incremental backups.
154+
155+
#### Restore Procedure
156+
157+
1. **Stop COSMOS**
158+
159+
```bash
160+
openc3.sh stop
161+
```
162+
163+
2. **Restore the MINIO backup.** Replace openc3-bucket-v with the actual container name:
164+
165+
```bash
166+
docker run --rm --user root -v openc3-bucket-v:/data \
167+
-v $(pwd):/backup openc3inc/openc3-init \
168+
sh -c "rm -rf /data/* && mc mirror --preserve /backup/minio /data && chown -R 501:501 /data && chmod -R 777 /data"
169+
```
170+
171+
3. **Restart COSMOS**
172+
173+
```bash
174+
openc3.sh start
175+
```

0 commit comments

Comments
 (0)