my-recipes/backend/TEST_BACKUP_SCHEDULE.md

143 lines
3.7 KiB
Markdown

# Test Scheduled Backup - 1 Minute Setup
## Quick Test Setup (1 Minute Interval)
### Step 1: Open Task Scheduler
1. Press `Win + R`
2. Type `taskschd.msc`
3. Press Enter
### Step 2: Create Test Task
1. Click **"Create Task"** (not Basic Task)
2. **General Tab:**
- Name: `Recipe DB Backup TEST`
- Description: `Test backup every 1 minute`
- Select "Run whether user is logged on or not"
- Check "Run with highest privileges"
### Step 3: Set 1-Minute Trigger
1. Go to **Triggers** tab
2. Click "New..."
3. Configure:
- Begin the task: `On a schedule`
- Settings: `Daily`
- Recur every: `1 days`
- Start: Set to current time (e.g., if it's 3:00 PM, set to 3:00 PM)
- Check "Repeat task every": `1 minute`
- For a duration of: `1 hour`
- Check "Enabled"
4. Click OK
### Step 4: Set Action
1. Go to **Actions** tab
2. Click "New..."
3. Configure:
- Action: `Start a program`
- Program/script: Browse to `run_backup.bat` or paste full path:
```
C:\Users\dvirl\OneDrive\Desktop\gitea\my-recipes\backend\run_backup.bat
```
- Start in:
```
C:\Users\dvirl\OneDrive\Desktop\gitea\my-recipes\backend
```
4. Click OK
### Step 5: Settings
1. Go to **Conditions** tab:
- Uncheck "Start the task only if the computer is on AC power"
2. Go to **Settings** tab:
- Check "Run task as soon as possible after a scheduled start is missed"
- Check "If the task fails, restart every: 1 minutes"
- Attempt to restart up to: `3 times`
- Check "Stop the task if it runs longer than: 30 minutes"
3. Click OK
4. Enter your Windows password when prompted
### Step 6: Monitor Test Results
**Check the backup log:**
```bash
cd C:\Users\dvirl\OneDrive\Desktop\gitea\my-recipes\backend
type backup.log
```
**Or open in Notepad:**
- Navigate to `backend\backup.log`
- Should see new entries every minute
**Check R2 bucket:**
- Login to Cloudflare Dashboard
- Go to R2 → my-recipes-db-bkp
- Should see new backup files appearing every minute
### Expected Log Output
```
[2025-12-21 15:30:45] Starting backup...
[2025-12-21 15:30:47] Creating database dump...
[2025-12-21 15:30:49] Compressing file...
[2025-12-21 15:30:51] Uploading to R2...
[2025-12-21 15:30:53] Backup completed: recipes_db_20251221_153045.sql.gz
[2025-12-21 15:30:53] Size: 2.5 MB
```
### Verify It's Working
Wait 2-3 minutes and check:
1. ✅ `backend\backup.log` has multiple entries
2. ✅ R2 bucket has new backup files
3. ✅ Task Scheduler shows "Last Run Result: (0x0)" = Success
### If It Works - Convert to Weekly
1. Open Task Scheduler
2. Find "Recipe DB Backup TEST"
3. Right-click → Properties
4. Go to **Triggers** tab
5. Edit the trigger:
- Settings: Change to `Weekly`
- Recur every: `1 weeks`
- Days: Select `Sunday` (or your preferred day)
- Time: `02:00:00` (2 AM)
- **Uncheck** "Repeat task every"
6. Click OK
7. **Rename task**: Right-click → Rename → "Recipe DB Weekly Backup"
### Troubleshooting
**No backup.log file:**
- Task might not be running
- Check Task Scheduler History tab
- Run `run_backup.bat` manually first
**backup.log shows errors:**
- Check if Python is in PATH
- Verify database credentials in `.env`
- Verify R2 credentials in `.env`
**Task shows "Could not start":**
- Verify the paths are correct
- Make sure you entered Windows password
- Try "Run" button in Task Scheduler manually
**Want to stop test:**
- Right-click task → Disable
- Or delete the task
### Manual Test First
Before setting up Task Scheduler, test manually:
```bash
cd C:\Users\dvirl\OneDrive\Desktop\gitea\my-recipes\backend
run_backup.bat
```
Check if:
1. backup.log is created
2. Backup appears in R2
3. No errors in log
If manual test works, Task Scheduler will work too!