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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hermes Memory Synchronization System
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
This system enables Hermes to backup and restore all persistent state to/from Hugging Face Datasets, ensuring data survives Docker restarts.
|
| 5 |
+
|
| 6 |
+
## Main File: hermes_sync.py
|
| 7 |
+
|
| 8 |
+
The `hermes_sync.py` script handles:
|
| 9 |
+
|
| 10 |
+
- **Backup**: Archives all of Hermes' state to a Hugging Face Dataset
|
| 11 |
+
- **Restore**: Recovers data from a Hugging Face Dataset back to Hermes
|
| 12 |
+
- **Auto-backup**: Automatic hourly backups (configurable via cron)
|
| 13 |
+
- **Auto-cleanup**: Automatically removes local backup files after successful upload
|
| 14 |
+
|
| 15 |
+
## What Gets Backed Up
|
| 16 |
+
|
| 17 |
+
The `hermes_sync.py` script backs up the following data from the `.hermes` directory:
|
| 18 |
+
|
| 19 |
+
- `state.db` + WAL - core KV state (sessions, memory, channel directory, etc.)
|
| 20 |
+
- `response_store.db` - chat response cache
|
| 21 |
+
- `sessions/` - session transcripts
|
| 22 |
+
- `skills/` - user-installed skills
|
| 23 |
+
- `cron/` - cron job definitions
|
| 24 |
+
- `memories/` - persistent memories
|
| 25 |
+
- `auth.json` - OAuth tokens
|
| 26 |
+
- `channel_directory.json` - registered channels
|
| 27 |
+
- `config.yaml` - active configuration
|
| 28 |
+
- `gateway_state.json` - gateway routing state
|
| 29 |
+
- `.env` - environment overrides
|
| 30 |
+
- `SOUL.md` - persona
|
| 31 |
+
- `.skills_prompt_snapshot.json` - skill snapshot
|
| 32 |
+
|
| 33 |
+
## What's Excluded
|
| 34 |
+
|
| 35 |
+
The following items are not backed up:
|
| 36 |
+
|
| 37 |
+
- `logs/` - runtime logs
|
| 38 |
+
- `plans/` - transient plans
|
| 39 |
+
- `workspace/` - user workspace (too large)
|
| 40 |
+
- `bin/` - binaries (reinstalled on start)
|
| 41 |
+
- `.update_check` - ephemeral data
|
| 42 |
+
- `auth.lock` - runtime lock file
|
| 43 |
+
|
| 44 |
+
## Usage
|
| 45 |
+
|
| 46 |
+
### 1. Download hermes_sync.py
|
| 47 |
+
|
| 48 |
+
Before using, download the script:
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
# Method 1: wget
|
| 52 |
+
wget https://huggingface.co/datasets/R1000/Hermes-Memory/resolve/main/hermes_sync.py
|
| 53 |
+
|
| 54 |
+
# Method 2: huggingface-cli
|
| 55 |
+
huggingface-cli download --repo-type dataset R1000/Hermes-Memory hermes_sync.py
|
| 56 |
+
|
| 57 |
+
# Method 3: curl
|
| 58 |
+
curl -O https://huggingface.co/datasets/R1000/Hermes-Memory/resolve/main/hermes_sync.py
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### 2. Set Environment Variables
|
| 62 |
+
|
| 63 |
+
Before using, set HF_TOKEN:
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
export HF_TOKEN=hf_your_token_here
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
Or in a `.env` file:
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
HF_TOKEN=hf_your_token_here
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### 3. Backup
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
# Create backup and upload to Hugging Face
|
| 79 |
+
python3 hermes_sync.py backup --upload
|
| 80 |
+
|
| 81 |
+
# Local backup file is created at /tmp/hermes_backup/hermes_memory_backup.zip
|
| 82 |
+
# After successful upload, local file is automatically deleted to save Docker space
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Note: Local backup files are automatically deleted after successful upload to prevent Docker space from filling up.
|
| 86 |
+
|
| 87 |
+
### 4. Restore
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
# Restore data from the latest backup on Hugging Face
|
| 91 |
+
python3 hermes_sync.py restore
|
| 92 |
+
|
| 93 |
+
# All data is fetched and extracted back to ~/.hermes/
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
### 5. Auto-backup Every Hour
|
| 97 |
+
|
| 98 |
+
```bash
|
| 99 |
+
# Start auto-backup service (runs in background)
|
| 100 |
+
python3 hermes_sync.py start
|
| 101 |
+
|
| 102 |
+
# Or use cron job:
|
| 103 |
+
# 0 * * * * cd /opt/data/.hermes/home && HF_TOKEN=xxx python3 hermes_sync.py backup --upload
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Setting Up Hourly Auto-backup
|
| 107 |
+
|
| 108 |
+
### Method 1: System Cron Job
|
| 109 |
+
|
| 110 |
+
Edit crontab:
|
| 111 |
+
|
| 112 |
+
```bash
|
| 113 |
+
crontab -e
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
Add this line (runs every hour at minute 0):
|
| 117 |
+
|
| 118 |
+
```bash
|
| 119 |
+
0 * * * * cd /opt/data/.hermes/home && export HF_TOKEN=hf_your_token && python3 hermes_sync.py backup --upload
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
### Method 2: Hermes Cron Job
|
| 123 |
+
|
| 124 |
+
Create a cron job through Hermes:
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
hermes cron create --schedule "0 * * * *" --name "hermes-auto-backup" --command "python3 hermes_sync.py backup --upload"
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
### Method 3: Python Schedule Library
|
| 131 |
+
|
| 132 |
+
The `hermes_sync.py` file includes a `start_auto_backup()` function that uses the schedule library:
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
python3 hermes_sync.py start
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## Security
|
| 139 |
+
|
| 140 |
+
- Token is stored only in environment variables, never hardcoded in files
|
| 141 |
+
- Backup files are compressed with ZIP_DEFLATED
|
| 142 |
+
- After successful upload, local files are automatically deleted
|
| 143 |
+
- No tokens are stored in the repository or public files
|
| 144 |
+
|
| 145 |
+
## File Locations
|
| 146 |
+
|
| 147 |
+
- Script file: `./hermes_sync.py` (after download)
|
| 148 |
+
- Local backup file: `/tmp/hermes_backup/` (automatically deleted after upload)
|
| 149 |
+
- Cloud backup file: `https://huggingface.co/datasets/R1000/Hermes-Memory`
|
| 150 |
+
|
| 151 |
+
## Usage Examples
|
| 152 |
+
|
| 153 |
+
### After Docker Restart
|
| 154 |
+
|
| 155 |
+
After restarting Docker:
|
| 156 |
+
|
| 157 |
+
```bash
|
| 158 |
+
# Download the script
|
| 159 |
+
wget https://huggingface.co/datasets/R1000/Hermes-Memory/resolve/main/hermes_sync.py
|
| 160 |
+
|
| 161 |
+
# Set token
|
| 162 |
+
export HF_TOKEN=hf_your_token
|
| 163 |
+
|
| 164 |
+
# Restore data
|
| 165 |
+
python3 hermes_sync.py restore
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
All data is restored from the latest backup.
|
| 169 |
+
|
| 170 |
+
### Immediate Backup
|
| 171 |
+
|
| 172 |
+
```bash
|
| 173 |
+
# Download file (if not already present)
|
| 174 |
+
wget https://huggingface.co/datasets/R1000/Hermes-Memory/resolve/main/hermes_sync.py
|
| 175 |
+
|
| 176 |
+
# Set token
|
| 177 |
+
export HF_TOKEN=hf_your_token
|
| 178 |
+
|
| 179 |
+
# Create backup and upload
|
| 180 |
+
python3 hermes_sync.py backup --upload
|
| 181 |
+
|
| 182 |
+
# Local backup file is automatically deleted after successful upload
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
## Troubleshooting
|
| 186 |
+
|
| 187 |
+
- Error: "HF_TOKEN environment variable is not set"
|
| 188 |
+
```bash
|
| 189 |
+
export HF_TOKEN=hf_your_token_here
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
- Error: "Upload failed"
|
| 193 |
+
- Check that HF_TOKEN is correct
|
| 194 |
+
- Check internet connectivity
|
| 195 |
+
- Check that the dataset has write permission
|
| 196 |
+
|
| 197 |
+
- Error: "Restore failed"
|
| 198 |
+
- Check that backup file exists on Hugging Face
|
| 199 |
+
- Check permissions on the `~/.hermes/` directory
|
| 200 |
+
|
| 201 |
+
## Important Notes
|
| 202 |
+
|
| 203 |
+
- The `hermes_sync.py` file is regularly updated at: https://huggingface.co/datasets/R1000/Hermes-Memory/blob/main/hermes_sync.py
|
| 204 |
+
- After successful upload, local backup files are automatically deleted
|
| 205 |
+
- Auto-backup runs every hour at minute 0 (or as scheduled)
|
| 206 |
+
- The system supports data recovery after Docker restarts
|