A professional-grade CLI tool for creating and restoring directory snapshots. snapdir captures complete directory structures and file contents into portable JSON snapshots, making it perfect for project templates, backups, and reproducible environments.
- Complete Snapshots: Captures directory structure, file contents, and permissions
- Smart Filtering: Automatic
.gitignoresupport + custom ignore patterns - File Size Protection: Configurable limits (default 100MB) prevent memory issues
- Cross-Platform: Handles path separators correctly on Windows, macOS, and Linux
- Verbose Mode: Detailed logging for debugging and monitoring
- Version Tracking: Snapshots include version metadata
- Safety Checks: Prevents accidental overwrites
- Comprehensive Testing: 60.6% test coverage with table-driven tests
git clone https://github.com/supperdoggy/snapdir.git
cd snapdir
go build -o snapdir ./cmd/go install github.com/supperdoggy/snapdir/cmd@latestsnapdir clone ./myproject snapshot.jsonsnapdir restore snapshot.json ./restored-projectsnapdir clone <source_dir> <output.json> [flags]Arguments:
source_dir: Directory to snapshotoutput.json: Output JSON file path
Flags:
-v, --verbose: Enable verbose logging--ignore <patterns>: Additional ignore patterns (comma-separated)--version: Show version information
Examples:
# Basic snapshot
snapdir clone ./myproject snapshot.json
# With verbose output
snapdir clone ./myproject snapshot.json -v
# With custom ignore patterns
snapdir clone ./myproject snapshot.json --ignore "*.tmp,*.cache,dist"
# Combine flags
snapdir clone ./myproject snapshot.json -v --ignore "node_modules,*.log"snapdir restore <config.json> <destination_dir> [flags]Arguments:
config.json: Snapshot JSON filedestination_dir: Where to restore (must not exist)
Flags:
-v, --verbose: Enable verbose logging--version: Show version information
Examples:
# Basic restore
snapdir restore snapshot.json ./restored
# With verbose output
snapdir restore snapshot.json ./restored -vsnapdir automatically respects .gitignore patterns in the source directory:
- Reads
.gitignorefrom the source directory root - Parses patterns (supports comments and empty lines)
- Applies patterns during snapshot creation
- Always excludes
.gitdirectory
Example .gitignore:
# Dependencies
node_modules/
vendor/
# Build outputs
dist/
build/
*.exe
# Logs
*.log
logs/
# Environment
.env
.env.localAdditional patterns can be specified via the --ignore flag:
snapdir clone ./project snapshot.json --ignore "temp,*.bak,cache"Patterns support:
- Wildcards:
*.log,*.tmp - Directory names:
node_modules,.cache - Exact filenames:
debug.log
Snapshots are stored as JSON with the following structure:
{
"version": "1.0.0",
"files": [
{
"path": "src/main.go",
"contents": "package main...",
"is_dir": false,
"mode": 420
},
{
"path": "src",
"is_dir": true,
"mode": 493
}
]
}Fields:
version: snapdir version used to create snapshotpath: Relative path (uses forward slashes)contents: File contents (omitted for directories)is_dir: Boolean indicating directorymode: Unix file permissions (octal in decimal)
Create reusable project templates:
# Create template
snapdir clone ./my-template template.json
# Use template for new projects
snapdir restore template.json ./new-project-1
snapdir restore template.json ./new-project-2Capture and share development environments:
# Developer A creates snapshot
snapdir clone ./working-env env-snapshot.json
# Developer B reproduces environment
snapdir restore env-snapshot.json ./my-envQuick directory backups:
# Create timestamped backup
snapdir clone ./important-files backup-$(date +%Y%m%d).json -vCreate test data fixtures:
# Snapshot test data
snapdir clone ./test-data test-fixture.json
# Restore for each test run
snapdir restore test-fixture.json ./test-temp- Go 1.23.4 or higher
go build -o snapdir ./cmd/# Run all tests
go test ./cmd/
# Run with verbose output
go test -v ./cmd/
# Run with coverage
go test -cover ./cmd/
# Generate coverage report
go test -coverprofile=coverage.out ./cmd/
go tool cover -html=coverage.outsnapdir/
├── cmd/
│ ├── main.go # Main application logic
│ └── main_test.go # Comprehensive test suite
├── go.mod # Go module definition
├── .gitignore # Git ignore patterns
└── README.md # This file
- Max file size: 100MB (files larger than this are skipped)
- Path format: Uses forward slashes in snapshots (cross-platform)
- Permissions: Preserves Unix file permissions (mode)
- Encoding: UTF-8 for file contents
snapdir provides detailed error messages with context:
- Path validation errors
- File access errors
- JSON parsing errors
- Directory creation errors
All errors use Go's error wrapping (%w) for proper error chains.
- No overwrites: Restore fails if destination exists
- Path validation: Checks for empty and non-existent paths
- File size limits: Prevents memory exhaustion
- Skip on errors: Invalid patterns logged but don't stop execution
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Write tests for new functionality
- Ensure all tests pass (
go test ./...) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Go's standard library
- Uses
filepath.WalkDirfor efficient directory traversal - Inspired by modern backup and templating tools
Made with Go | Report Bug | Request Feature