2.8 KiB
2.8 KiB
Weekly Backup Setup - Windows Task Scheduler
This guide will help you set up automatic weekly backups of your database.
Setup Instructions
1. Create Batch Script
Create a file run_backup.bat in the backend folder:
@echo off
cd /d "%~dp0"
python backup_db.py >> backup.log 2>&1
2. Open Task Scheduler
- Press
Win + R - Type
taskschd.msc - Press Enter
3. Create New Task
- Click "Create Task" (not "Create Basic Task")
- In General tab:
- Name:
Recipe DB Weekly Backup - Description:
Automatic weekly database backup to Cloudflare R2 - Select "Run whether user is logged on or not"
- Check "Run with highest privileges"
- Name:
4. Configure Trigger
- Go to Triggers tab
- Click "New..."
- Configure:
- Begin the task:
On a schedule - Settings:
Weekly - Recur every:
1 weeks - Days: Select
Sunday(or your preferred day) - Time:
02:00:00(2 AM) - Check "Enabled"
- Begin the task:
- Click OK
5. Configure Action
- Go to Actions tab
- Click "New..."
- Configure:
- Action:
Start a program - Program/script:
C:\Path\To\backend\run_backup.bat(Replace with your actual path) - Start in:
C:\Path\To\backend\(Replace with your actual path)
- Action:
- Click OK
6. Additional Settings
-
Go to Conditions tab:
- Uncheck "Start the task only if the computer is on AC power"
-
Go to Settings tab:
- Check "Run task as soon as possible after a scheduled start is missed"
- If the task fails, restart every:
10 minutes - Attempt to restart up to:
3 times
-
Click OK
7. Enter Password
- You'll be prompted to enter your Windows password
- This allows the task to run even when you're not logged in
Verify Setup
Test the Task
- In Task Scheduler, find your task
- Right-click → "Run"
- Check
backend/backup.logfor results
View Scheduled Runs
- In Task Scheduler, select your task
- Check the "History" tab to see past runs
Troubleshooting
Task doesn't run
- Check Task Scheduler → Task History for errors
- Verify Python is in system PATH
- Try running
run_backup.batmanually first
No log file created
- Check file permissions in backend folder
- Verify the "Start in" path is correct
Backup fails
- Check
backend/backup.logfor error messages - Verify database credentials in
.env - Verify R2 credentials in
.env - Test by running
python backup_db.pymanually
Change Backup Schedule
- Open Task Scheduler
- Find "Recipe DB Weekly Backup"
- Right-click → Properties
- Go to Triggers tab
- Edit the trigger to change day/time
- Click OK
Disable Automatic Backups
- Open Task Scheduler
- Find "Recipe DB Weekly Backup"
- Right-click → Disable
View Backup Log
Check backend/backup.log to see backup history:
cd backend
type backup.log
Or open it in Notepad.