siyuan-note/siyuan · error
unsupported notebook crypto backup spec
Error message
unsupported notebook crypto backup spec [%d]
What it means
loadNotebookCryptoBackup reads the backup file and unmarshals it into conf.NotebookCrypto, then rejects any backup whose Spec field differs from conf.CurrentNotebookCryptoSpec. This ensures the kernel only restores backups written in the exact supported format version; older or newer (unknown) spec numbers are refused rather than guessed at.
Solutions
- Upgrade the kernel/app to a version whose conf.CurrentNotebookCryptoSpec matches the backup's spec value
- If downgrading is required, first export/recover notebooks through the newer version before switching
- Verify the backup file is intact and contains the correct spec field; restore from a known-good backup
- Do not hand-edit the spec value — restore the original backup instead
Example fix
// before (hand-edited backup)
{"spec": 0, ...}
// after (restored from a compatible version's backup)
{"spec": <CurrentNotebookCryptoSpec>, ...} Defensive patterns
Strategy: fallback
Validate before calling
var probe struct{ Spec int `json:"spec"` }
if err := json.Unmarshal(raw, &probe); err != nil || probe.Spec != conf.CurrentNotebookCryptoSpec {
return errors.New("backup spec version is not supported by this kernel version")
} Try / catch
if _, err := loadNotebookCryptoBackup(); err != nil {
if strings.Contains(err.Error(), "unsupported notebook crypto backup spec") {
// direct user to upgrade (or export via the matching version)
}
return err
} Prevention
- Do not downgrade the app across crypto backup format bumps without exporting first
- Keep backups produced by the running version; regenerate the backup after version upgrades
- Never hand-edit the spec field in backup JSON
When it happens
Trigger: Loading a backup file whose JSON 'spec' value is not the current spec constant — e.g. a backup produced by an older SiYuan version before a format bump, a newer backup read by an older kernel, or a corrupted file where unmarshal left Spec at 0/default. Raised from restoreNotebookCryptoConfigFromBackup, deriveNotebookCryptoBackupCandidate, and deriveKEK paths.
Common situations: Downgrading the app after the crypto backup format was bumped; restoring a data directory copied from a newer installation; hand-edited or truncated backup JSON losing the spec field (defaults to 0); TestBackupRejectsIncompleteCurrentSpec-style corruption.
Related errors
- cannot write incomplete notebook crypto backup
- notebook crypto backup is incomplete or corrupted
- master password migration is pending
- requires a 32-byte (AES-256) key
- 346
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/30a676f66f17b690.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:494
}
return true
}
// loadNotebookCryptoBackup 从 DataDir 读取 NotebookCrypto 备份。文件不存在返回 (nil, nil)。
func loadNotebookCryptoBackup() (*conf.NotebookCrypto, error) {
data, err := filelock.ReadFile(dataCryptoBackupPath())
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
nc := &conf.NotebookCrypto{}
if err := json.Unmarshal(data, nc); err != nil {
return nil, err
}
if nc.Spec != conf.CurrentNotebookCryptoSpec {
return nil, fmt.Errorf("unsupported notebook crypto backup spec [%d]", nc.Spec)
}
if !notebookCryptoConfigurationComplete(nc) {
return nil, errors.New("notebook crypto backup is incomplete or corrupted")
}
return nc, nil
}
// removeNotebookCryptoBackup 删除备份文件(禁用加密功能时调用)。文件不存在视为成功。
func removeNotebookCryptoBackup() {
if err := os.Remove(dataCryptoBackupPath()); err != nil && !os.IsNotExist(err) {
logging.LogErrorf("remove notebook crypto backup failed: %s", err)
}
}
// masterPasswordMigration 记录改密迁移的完整状态,用于崩溃后恢复。
type masterPasswordMigration struct {
OldVerifier []byte `json:"oldVerifier"`
NewVerifier []byte `json:"newVerifier"`View on GitHub (pinned to 9f775e8a12)