Backup & Recovery
Protect your repositories with robust backup strategies and know how to recover from data loss, corruption, or accidental deletions.
Distributed by Design
Dits repositories are inherently distributed. Every clone is a full backup. The more team members, the more redundancy you have.
Backup Strategies
Multiple Remotes
Push to multiple backup locations
# Add backup remotes
dits remote add backup-s3 s3://bucket/repo
dits remote add backup-gcs gs://bucket/repo
# Push to all remotes
dits push --all origin backup-s3 backup-gcsBundle Export
Create portable backup files
# Export entire repo to file
dits bundle create backup.bundle --all
# Include only recent history
dits bundle create recent.bundle main~100..mainAutomated Backup Script
#!/bin/bash
# backup-repos.sh - Run via cron
BACKUP_DIR="/backups/dits"
DATE=$(date +%Y-%m-%d)
for repo in /repos/*/.dits; do
REPO_DIR=$(dirname "$repo")
REPO_NAME=$(basename "$REPO_DIR")
cd "$REPO_DIR"
# Create bundle backup
dits bundle create "$BACKUP_DIR/$REPO_NAME-$DATE.bundle" --all
# Push to backup remotes
dits push backup-s3 --all --tags
# Keep only last 30 days locally
find "$BACKUP_DIR" -name "$REPO_NAME-*.bundle" -mtime +30 -delete
echo "Backed up $REPO_NAME"
doneRecovery Scenarios
Recover from Bundle
# List bundle contents
$ dits bundle list-heads backup.bundle
refs/heads/main
refs/heads/develop
refs/tags/v1.0.0
# Clone from bundle
$ dits clone backup.bundle restored-repo
$ cd restored-repo
# Re-add remote and sync
$ dits remote add origin https://server/repo
$ dits fetch origin
$ dits push origin --all --tagsRecover Deleted Branch
# Find the deleted branch in reflog
$ dits reflog
abc1234 HEAD@{0}: checkout: moving from deleted-branch to main
def5678 HEAD@{1}: commit: Last commit on deleted-branch
...
# Restore the branch
$ dits checkout -b deleted-branch def5678
Branch 'deleted-branch' restored.Recover Deleted Commits
# Find lost commits
$ dits fsck --lost-found
Checking objects...
dangling commit abc1234: "Important work"
dangling commit def5678: "More changes"
# Recover specific commit
$ dits checkout -b recovered abc1234
# Or cherry-pick to current branch
$ dits cherry-pick abc1234Recover from Corrupted Repository
# Check repository integrity
$ dits fsck --full
Checking objects...
error: corrupt object abc1234
error: missing chunk def5678
# Attempt repair from remote
$ dits fetch origin --repair
Fetching missing objects...
Recovered: abc1234
Recovered chunk: def5678
Repository repaired.
# If remote not available, use backup
$ dits remote add backup file:///backups/repo.bundle
$ dits fetch backup --repairChunk-Level Recovery
Dits can recover individual corrupted chunks from any source that has them, including team members' machines via P2P.
Recover Specific File Version
# Find file in history
$ dits log --all -- project.prproj
commit abc1234 (3 days ago)
Final cut approved
commit def5678 (1 week ago)
Client revision 2
# Restore file from specific commit
$ dits checkout abc1234 -- project.prproj
Updated 'project.prproj' from commit abc1234
# Or save as different name
$ dits show abc1234:project.prproj > project-backup.prprojReflog - Your Safety Net
# View reflog (30 days history)
$ dits reflog
abc1234 HEAD@{0}: commit: Add new feature
def5678 HEAD@{1}: pull: Fast-forward
111aaa HEAD@{2}: reset: moving to HEAD~3
222bbb HEAD@{3}: commit: Work in progress
...
# Undo last operation
$ dits reset --hard HEAD@{1}
HEAD is now at def5678
# View reflog for specific branch
$ dits reflog show feature/branch
# Increase reflog retention
$ dits config gc.reflogExpire 90.daysVerification & Health Checks
# Full integrity check
$ dits fsck --full
Checking object directories...
Checking objects...
Checking connectivity...
All objects OK.
# Verify chunk integrity
$ dits verify-chunks
Verified 45,678 chunks. All OK.
# Regular maintenance
$ dits gc
Counting objects: 12,345
Compressing objects: 100%
Removing unreachable objects
Done.
# Check repository size
$ dits count-objects -vH
count: 12,345
size: 2.3 GB
prune-packable: 234
gc: 0 packsBest Practices
Backup Schedule
- Hourly: Push to backup remote
- Daily: Create bundle backup
- Weekly: Verify backup integrity
- Monthly: Test restore procedure
Redundancy Rules
- Minimum 3 copies (3-2-1 rule)
- 2 different storage types
- 1 offsite location
- Test restores regularly
Disaster Recovery Plan
Recovery Steps
- 1. Assess damage
Run
dits fsck --fullto identify corruption extent. - 2. Try remote repair
Use
dits fetch origin --repairto recover from central server. - 3. P2P recovery
If available, use
dits p2p sync --repairfrom team machines. - 4. Bundle restore
Clone from most recent bundle backup if other methods fail.
- 5. Verify and resume
Run
dits fsckagain, then resume work.
Related Topics
- Maintenance Commands - gc, fsck, prune
- Deployment - Server backup
- Security - Encryption and access