# Backup Scripts

Automated backup system for WorkRoot website.

## Quick Start

```bash
# First-time setup
mkdir -p backups/{daily,weekly,monthly,pre-deploy,incremental,safety}

# Create your first backup
npm run backup:full

# Verify it worked
npm run backup:verify
```

## Available Commands

| Command | Description |
|---------|-------------|
| `npm run backup:full` | Full backup of all critical files |
| `npm run backup:content` | Quick backup of content only |
| `npm run backup:config` | Backup configs and env files |
| `npm run backup:verify` | Check backup health and integrity |
| `npm run backup:list` | List all available backups |
| `npm run backup:restore` | Restore from backup (interactive) |
| `npm run backup:cleanup` | Remove old backups per retention policy |

## Automation Setup

### Linux/macOS (cron)

```bash
# Edit crontab
crontab -e

# Daily backup at 2 AM
0 2 * * * cd /path/to/project && npm run backup:full

# Cleanup weekly on Sunday at 3 AM
0 3 * * 0 cd /path/to/project && npm run backup:cleanup
```

### Windows (Task Scheduler)

```powershell
# Daily backup
schtasks /create /tn "WorkRoot-DailyBackup" /tr "npm run backup:full" /sc daily /st 02:00

# Weekly cleanup
schtasks /create /tn "WorkRoot-CleanupBackup" /tr "npm run backup:cleanup" /sc weekly /d SUN /st 03:00
```

## Restore Examples

```bash
# List available backups
npm run backup:list

# Restore from latest
npm run backup:restore backups/daily/latest-full.tar.gz

# Verify specific backup
npm run backup:verify backups/daily/full-backup-2026-03-21.tar.gz
```

## Storage Structure

```
backups/
├── daily/          # 7 days retention
├── weekly/         # 4 weeks retention
├── monthly/        # 3 months retention
├── incremental/    # 72 hours retention
├── pre-deploy/     # Last 10 deployments
└── safety/         # Pre-restore backups (30 days)
```

## Pre-Deployment

Always backup before deployment:

```bash
# Manual
npm run backup:config

# Automatic (in deployment script)
npm run deploy  # Includes automatic config backup
```

## Troubleshooting

### Backup fails

```bash
# Check disk space
df -h

# Check permissions
ls -la backups/

# Make scripts executable
chmod +x scripts/backup/*.sh
```

### Restore fails

```bash
# Verify backup integrity
npm run backup:verify backups/daily/backup-file.tar.gz

# Check backup contents
tar -tzf backups/daily/backup-file.tar.gz
```

## Documentation

See [BACKUP_STRATEGY.md](../../.agents/devops-engineer/BACKUP_STRATEGY.md) for complete documentation.
