Claude-skill-registry db-wal-recovery
Guide for recovering data from SQLite Write-Ahead Log (WAL) files that may be corrupted, encrypted, or inaccessible through standard methods. This skill should be used when tasks involve SQLite database recovery, WAL file analysis, encrypted database files, or discrepancies between tool outputs and filesystem access.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/db-wal-recovery" ~/.claude/skills/majiayu000-claude-skill-registry-db-wal-recovery && rm -rf "$T"
skills/data/db-wal-recovery/SKILL.mdSQLite WAL File Recovery
Overview
This skill provides systematic approaches for recovering data from SQLite Write-Ahead Log (WAL) files. WAL recovery tasks often involve files that are corrupted, encrypted, or exhibit unusual access patterns. The skill emphasizes thorough investigation over pattern-guessing and provides verification strategies to ensure actual data recovery rather than fabrication.
Critical Principle: Never Guess Data
When recovering database records, the goal is to recover actual data, not to generate plausible data based on patterns. If data cannot be recovered through technical means, acknowledge failure rather than fabricate records.
Investigation Workflow
Phase 1: Environment Discovery
Before attempting recovery, conduct thorough environment discovery:
-
Inventory all files using multiple methods:
- Use built-in tool commands (e.g.,
,LS
) to list directory contentsRead - Use bash commands (
,ls -la
,find
) independentlylocate - Compare outputs—discrepancies are significant clues
- Use built-in tool commands (e.g.,
-
Check for discrepancies between tools and bash:
- If a built-in tool shows a file exists but bash cannot access it, this indicates special access requirements
- Document the exact discrepancy: tool name, output shown, bash command tried, bash result
- This discrepancy often indicates encrypted filesystems, virtual files, or special permissions
-
Examine the environment for clues:
- Check environment variables for encryption keys or paths
- Look for configuration files (.env, config.json, .sqlite*, etc.)
- Search for related files (key files, password files, encrypted containers)
Phase 2: File Analysis
When a WAL file is located:
-
Examine file headers:
- Valid SQLite WAL files start with magic bytes:
(hex) or specific WAL header signature377f0682 - Check byte offsets 0-32 for WAL header structure
- Compare against documented SQLite WAL format (see references/wal_format.md)
- Valid SQLite WAL files start with magic bytes:
-
Analyze binary structure:
- Use
orxxd
for initial inspectionhexdump - Look for recognizable patterns (ASCII strings, repeated structures)
- Identify frame boundaries in WAL files
- Use
-
Detect encryption or corruption:
- High entropy throughout = likely encrypted
- Valid header but corrupted frames = partial corruption
- No recognizable structure = unknown encoding or encryption
Phase 3: Recovery Approaches
Attempt recovery methods in order of likelihood:
For Encrypted Files
-
Search for decryption keys:
- Environment variables
- Adjacent files (*.key, *.pem, config files)
- Database pragmas (PRAGMA key for SQLCipher)
-
Try common encryption schemes:
- SQLCipher (most common SQLite encryption)
- SEE (SQLite Encryption Extension)
- Custom XOR with multi-byte keys (not just single-byte)
- AES-256-CBC with standard key derivation
-
Test multiple key formats:
- Raw bytes
- Hex-encoded strings
- Base64-encoded keys
- Passphrase-based derivation (PBKDF2)
For Corrupted Files
-
Attempt SQLite recovery tools:
commandsqlite3 .recover
to extract what's possible.dump- Third-party tools like
orundarksqlite-recover
-
Manual page reconstruction:
- Identify valid WAL frames
- Extract page data from intact frames
- Apply changes to database manually
-
Partial recovery:
- Extract readable text strings with
commandstrings - Parse individual records from binary data
- Reconstruct table structure from fragments
- Extract readable text strings with
For Virtual/Inaccessible Files
When tools show a file that bash cannot access:
-
Investigate the access method:
- The tool showing the file has special access—understand how
- Try reading through the same tool that listed the file
- Look for mount points, FUSE filesystems, or encrypted containers
-
Check for special filesystems:
- EncFS, gocryptfs, or similar encrypted filesystems
- FUSE-mounted virtual filesystems
- Container-based isolation
-
Examine tool capabilities:
- Some tools may have built-in decryption
- Check tool documentation for special file handling
- Try tool-specific read commands
Verification Strategies
Before Declaring Success
-
Verify recovered data makes sense:
- Check data types match expected schema
- Validate relationships between records
- Compare against known valid records
-
Cross-reference with database:
- Query the main database for gaps or references to missing data
- Check foreign key relationships
- Examine indexes for expected entries
-
Test data integrity:
- Run
PRAGMA integrity_check - Verify transaction consistency
- Check checkpoint status
- Run
Red Flags Indicating Incorrect Approach
- Finding yourself "guessing" what data should be
- Relying on pattern recognition rather than actual data extraction
- Multiple arbitrary choices for the same record
- High uncertainty about recovered values
- No binary data supporting the recovered values
Common Pitfalls
Pitfall 1: Abandoning Investigation Too Early
Wrong: Conclude file doesn't exist after a few bash commands fail Right: Investigate why built-in tools showed different results; the discrepancy is a clue
Pitfall 2: Single-Method Encryption Testing
Wrong: Try only single-byte XOR and conclude file isn't encrypted Right: Test multiple encryption schemes, key lengths, and formats systematically
Pitfall 3: Pattern-Based Data Generation
Wrong: Notice alphabetical pattern and generate next items in sequence Right: Recovery means extracting actual data; if data cannot be extracted, acknowledge failure
Pitfall 4: Ignoring WAL File Structure
Wrong: Treat WAL as opaque binary blob Right: Parse according to documented SQLite WAL format to identify frames and pages
Pitfall 5: Missing Environmental Clues
Wrong: Focus only on the database files Right: Search entire environment for keys, configuration, related files
Escalation Checklist
If standard recovery fails, verify completion of:
- Compared tool output vs bash output for all file operations
- Searched for encryption keys in environment and adjacent files
- Tested at least 5 different encryption/encoding schemes
- Examined WAL file structure against documented format
- Attempted SQLite built-in recovery commands
- Tried reading through same tool that originally showed the file
- Checked for special filesystems or mount points
- Extracted and analyzed any readable string content
- Documented specific technical blockers preventing recovery
Only after completing this checklist should recovery be considered impossible.
Resources
Reference documentation for detailed technical specifications:
- SQLite WAL file format specification and structurereferences/wal_format.md