# GitHub Cloud Backup Setup Guide

## 🎯 Quick Setup (5 minutes)

### Step 1: Create GitHub Repository

1. Go to: **https://github.com/new**
2. Repository name: `erp-codearya-backup` (or any name you like)
3. **Make it PRIVATE** (important for security!)
4. **DO NOT** check "Initialize with README"
5. Click **"Create repository"**

### Step 2: Run Setup Script

```bash
cd /var/www/html/erp_codearya
./setup-github-backup.sh
```

The script will:
- ✅ Ask for your GitHub repository URL
- ✅ Configure remote backup
- ✅ Push all existing backups to GitHub
- ✅ Enable auto-push after each build

### Step 3: Authentication

**Option A: HTTPS (Easier)**
- Use your GitHub username
- Use a **Personal Access Token** as password (not your GitHub password)
- Create token: https://github.com/settings/tokens
- Select scopes: `repo` (full control of private repositories)

**Option B: SSH (More Secure)**
- Generate SSH key: `ssh-keygen -t ed25519 -C "your_email@example.com"`
- Add to GitHub: https://github.com/settings/keys
- Use SSH URL: `git@github.com:USERNAME/REPO.git`

## ✅ After Setup

### Automatic Backup
Every time you run:
```bash
./build-with-backup.sh
```

It will:
1. Create local backup
2. **Automatically push to GitHub** (cloud backup)
3. Save build tag

### Manual Push
If auto-push fails, push manually:
```bash
git push origin master --tags
```

### Check Backup Status
```bash
./check-backup-location.sh
```

## 🔒 Security

- ✅ Use **PRIVATE** repositories (not public)
- ✅ Don't commit `.env` files (already in .gitignore)
- ✅ Use Personal Access Tokens (not passwords)
- ✅ Enable 2FA on GitHub account

## 📋 What Gets Backed Up

✅ **Included:**
- All source code
- All commits
- All build tags
- Configuration files

❌ **Excluded** (via .gitignore):
- `node_modules/`
- `target/` (build artifacts)
- `.env` files
- Logs
- Uploads

## 🆘 Troubleshooting

### "Authentication failed"
- For HTTPS: Use Personal Access Token, not password
- For SSH: Add SSH key to GitHub account

### "Repository not found"
- Check repository name and URL
- Make sure repository exists on GitHub
- Verify you have access to the repository

### "Push failed"
- Check internet connection
- Verify GitHub credentials
- Try: `git push origin master --tags` manually

## 📊 Verify Backup

```bash
# Check remote status
git remote -v

# Check last push
git log origin/master -1

# List all backups
./list-builds.sh
```

## 🎉 Benefits

- ✅ **Cloud Storage**: Backups stored off-site
- ✅ **Automatic**: No manual steps needed
- ✅ **Safe**: Can restore even if server fails
- ✅ **Accessible**: View backups from anywhere
- ✅ **Free**: GitHub private repos are free

---

**Ready to set up?** Run: `./setup-github-backup.sh`
