Edit file File name : SETUP.md Content :# Database Backup Manager - Setup Guide A Laravel application for managing database backups with Google Drive integration and automated scheduling. ## Features 1. **Database Configuration Management** - Add multiple database configurations - Store host, port, database name, username, and password - Enable/disable databases 2. **Google Drive Integration** - OAuth 2.0 authentication - Automatic backup upload to Google Drive - Secure token management 3. **Backup Management** - Manual backup triggers - View backup history - Track successful and failed backups - File size tracking 4. **Automated Scheduling** - Configurable backup schedules (hourly, daily, weekly, monthly) - Laravel task scheduler integration - Next run time tracking ## Installation Steps ### 1. Install Dependencies ```bash composer install ``` ### 2. Environment Configuration Copy `.env.example` to `.env`: ```bash cp .env.example .env ``` Generate application key: ```bash php artisan key:generate ``` ### 3. Database Setup Configure your database in `.env`: ```env DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=backup_manager DB_USERNAME=root DB_PASSWORD= ``` Run migrations: ```bash php artisan migrate ``` ### 4. Google Drive Setup #### A. Create Google Cloud Project 1. Go to [Google Cloud Console](https://console.cloud.google.com/) 2. Create a new project or select existing one 3. Enable **Google Drive API** - Navigate to "APIs & Services" > "Library" - Search for "Google Drive API" - Click "Enable" #### B. Create OAuth 2.0 Credentials 1. Go to "APIs & Services" > "Credentials" 2. Click "Create Credentials" > "OAuth client ID" 3. Choose "Web application" 4. Add authorized redirect URI: ``` http://localhost:8000/google-drive/callback ``` (Change this to your actual domain in production) 5. Copy the Client ID and Client Secret #### C. Configure Environment Variables Add to your `.env` file: ```env GOOGLE_CLIENT_ID=your_client_id_here GOOGLE_CLIENT_SECRET=your_client_secret_here GOOGLE_REDIRECT_URI=http://localhost:8000/google-drive/callback ``` ### 5. Start the Application ```bash php artisan serve ``` Visit: `http://localhost:8000` ### 6. Setup Cron Job (For Automated Backups) Add to your crontab: ```bash * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 ``` This runs every minute and checks for scheduled backups. ## Usage Guide ### 1. Connect Google Drive 1. Go to the Dashboard 2. Click "Connect Google Drive" 3. Authorize the application 4. You'll be redirected back to the dashboard ### 2. Add Database Configuration 1. Navigate to "Databases" 2. Click "Add Database" 3. Fill in the form: - **Name**: Friendly name for the database - **Host**: Database server hostname - **Port**: Database port (default: 3306) - **Database**: Database name - **Username**: Database username - **Password**: Database password 4. Click "Save" ### 3. Run Manual Backup 1. Go to Dashboard or Databases page 2. Click "Backup Now" next to the database 3. The backup will be created and uploaded to Google Drive ### 4. Setup Backup Schedule 1. Navigate to "Schedules" 2. Click "Create Schedule" 3. Select: - **Database**: Which database to backup - **Frequency**: hourly, daily, weekly, or monthly - **Time**: Specific time for daily/weekly/monthly backups - **Day**: Day of week for weekly, or day of month for monthly 4. Click "Save" ### 5. View Backup History 1. Navigate to "Backup History" 2. View all backups with: - Database name - Filename - File size - Status (success/failed) - Google Drive file ID - Timestamp ## File Structure ``` app/ ├── Console/Commands/ │ └── RunScheduledBackups.php # Scheduled backup command ├── Http/Controllers/ │ ├── BackupController.php # Backup management │ ├── DatabaseConfigurationController.php │ ├── DashboardController.php │ └── GoogleDriveController.php # Google Drive OAuth ├── Models/ │ ├── BackupHistory.php │ ├── BackupSchedule.php │ ├── DatabaseConfiguration.php │ └── GoogleDriveSetting.php └── Services/ ├── BackupService.php # Core backup logic └── GoogleDriveService.php # Google Drive operations database/migrations/ ├── *_create_database_configurations_table.php ├── *_create_backup_histories_table.php ├── *_create_backup_schedules_table.php └── *_create_google_drive_settings_table.php resources/views/ ├── layouts/ │ └── app.blade.php # Main layout └── dashboard.blade.php # Dashboard view ``` ## Security Notes 1. **Never commit `.env` file** - It contains sensitive credentials 2. **Database passwords are stored encrypted** - Use Laravel's encryption if needed 3. **Google Drive tokens are stored securely** in the database 4. **Backup files contain sensitive data** - Ensure proper access controls ## Troubleshooting ### MySQL Dump Not Working Make sure `mysqldump` is in your system PATH: ```bash which mysqldump # Linux/Mac where mysqldump # Windows ``` ### Google Drive Upload Fails 1. Check that Google Drive API is enabled 2. Verify OAuth credentials in `.env` 3. Ensure redirect URI matches exactly in Google Cloud Console 4. Check token expiry - reconnect if needed ### Scheduler Not Running Verify cron job is set up correctly: ```bash crontab -l ``` Test manually: ```bash php artisan backups:run-scheduled ``` ## API Endpoints | Method | Route | Description | |--------|-------|-------------| | GET | `/` | Dashboard | | GET | `/databases` | List databases | | POST | `/databases` | Create database config | | PUT | `/databases/{id}` | Update database config | | DELETE | `/databases/{id}` | Delete database config | | GET | `/backups` | Backup history | | POST | `/backups/run/{database}` | Run manual backup | | GET | `/backups/schedules` | List schedules | | POST | `/backups/schedules` | Create schedule | | DELETE | `/backups/schedules/{id}` | Delete schedule | | GET | `/google-drive/authorize` | Start OAuth flow | | GET | `/google-drive/callback` | OAuth callback | | POST | `/google-drive/disconnect` | Disconnect Google Drive | ## Backup File Location Local backups are stored in: ``` storage/app/backups/ ``` ## Next Steps To complete the UI, you need to create additional views: 1. `resources/views/databases/index.blade.php` - List all databases 2. `resources/views/databases/create.blade.php` - Add new database form 3. `resources/views/databases/edit.blade.php` - Edit database form 4. `resources/views/backups/index.blade.php` - Backup history list 5. `resources/views/backups/schedules.blade.php` - Schedule management These views should follow the same pattern as the dashboard view, using Tailwind CSS for styling. ## Support For issues or questions, refer to: - [Laravel Documentation](https://laravel.com/docs) - [Google Drive API Documentation](https://developers.google.com/drive) - [Spatie Laravel Backup](https://spatie.be/docs/laravel-backup) Save