siyuan-note/siyuan · error
write notebook crypto backup failed
Error message
write notebook crypto backup failed: %w
What it means
saveNotebookCryptoBackup wraps an atomicWriteFile failure for <DataDir>/.siyuan/data-crypto-backup.json as "write notebook crypto backup failed: %w". The configuration was already validated and copied into Conf, but the durable backup file could not be written atomically; Conf now references a BackupID whose file may not exist, so this must be resolved before the backup can be considered reliable.
Solutions
- Free disk space on the data volume if ENOSPC
- Fix ownership/permissions of <DataDir>/.siyuan/data-crypto-backup.json and its directory
- Close programs locking the file (antivirus, sync clients) and retry the operation that triggered the save
- Inspect the wrapped OS error for the precise cause and address it (EACCES/EROFS/EIO)
- After fixing, re-run the enabling/password-change flow so the backup file is regenerated and matches Conf.BackupID
Example fix
# before $ ls -l <DataDir>/.siyuan/data-crypto-backup.json # read-only, stale # after $ rm <DataDir>/.siyuan/data-crypto-backup.json # or chmod u+w $ # re-run enable-encryption / change-password to regenerate the backup
Defensive patterns
Strategy: retry
Validate before calling
p := dataCryptoBackupPath()
if fi, err := os.Stat(p); err == nil && fi.Mode().Perm()&0200 == 0 {
return errors.New("backup file not writable: " + p)
}
if err := unix.Access(filepath.Dir(p), unix.W_OK); err != nil {
return errors.New("backup dir not writable")
} Type guard
null
Try / catch
if err := saveNotebookCryptoBackup(kek); err != nil {
if strings.Contains(err.Error(), "write notebook crypto backup failed") {
// resolve wrapped OS error (ENOSPC/EACCES/EIO), then re-run the triggering flow
// so the backup file is regenerated and matches Conf.BackupID
}
} Prevention
- Monitor disk space and volume health on the data partition
- Keep the backup file writable by the kernel process user
- Exclude data-crypto-backup.json from external lockers (sync/AV clients)
- After any write failure and fix, re-run enable/password-change to regenerate the backup rather than trusting stale state
When it happens
Trigger: Any saveNotebookCryptoBackup call (via EnableEncryptedNotebook, deriveKEK, ChangeMasterPassword) where atomicWriteFile fails — permission denied on the target file, disk full, target file locked by another process/antivirus, or I/O error on the volume.
Common situations: Full disk right after enabling encryption; the previous backup file is read-only or owned by root; sync/backup software holding the file open on Windows; failing disk producing EIO.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- cannot allocate a replacement history directory
- create import dir failed
- enable encrypted notebook failed: failed to persist key…
- failed to persist key backup
- mkdir notebook crypto backup dir failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/f5f94acee69a5999.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:407
Conf.m.Unlock()
return errors.New("cannot save incomplete notebook crypto configuration")
}
Conf.NotebookCrypto.Spec = nc.Spec
Conf.NotebookCrypto.BackupID = nc.BackupID
Conf.NotebookCrypto.CreatedAt = nc.CreatedAt
Conf.NotebookCrypto.Checksum = nc.Checksum
Conf.NotebookCrypto.KEKMAC = nc.KEKMAC // 保持 Conf 与备份文件的 KEKMAC 一致
Conf.m.Unlock()
backupPath := dataCryptoBackupPath()
if err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {
return fmt.Errorf("mkdir notebook crypto backup dir failed: %w", err)
}
data, err := json.Marshal(nc)
if err != nil {
return fmt.Errorf("marshal notebook crypto backup failed: %w", err)
}
if err := atomicWriteFile(backupPath, data); err != nil {
return fmt.Errorf("write notebook crypto backup failed: %w", err)
}
return nil
}
// writeNotebookCryptoBackupData 将指定的 NotebookCrypto 写入备份文件(不依赖 Conf.NotebookCrypto)。
// kek 必须非 nil:在 Checksum 定型后计算 KEKMAC,保证落盘 MAC 与落盘内容一致。
func writeNotebookCryptoBackupData(nc *conf.NotebookCrypto, kek []byte) error {
if kek == nil {
return errors.New("cannot generate notebook crypto backup without KEK")
}
prepareBackupForWrite(nc)
nc.KEKMAC = computeKEKMAC(nc, kek)
if !notebookCryptoConfigurationComplete(nc) {
return errors.New("cannot write incomplete notebook crypto backup")
}
backupPath := dataCryptoBackupPath()
if err := os.MkdirAll(filepath.Dir(backupPath), 0755); err != nil {
return fmt.Errorf("mkdir notebook crypto backup dir failed: %w", err)View on GitHub (pinned to 9f775e8a12)