Download the PHP package marekmiklusek/database-backup without Composer
On this page you can find all versions of the php package marekmiklusek/database-backup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marekmiklusek/database-backup
More information about marekmiklusek/database-backup
Files in marekmiklusek/database-backup
Package database-backup
Short Description A Laravel package for database backups.
License MIT
Informations about the package database-backup
Laravel Database Backup πΎππ
A lightweight package for automated MySQL database backups in Laravel applications. This package seamlessly integrates with both local storage and Google Drive, providing a reliable solution for database backup management.
Features
- Simple and automated MySQL database backups
- Multiple storage options:
- Local storage
- Google Drive integration
- Simultaneous backup to multiple locations
- Command-line interface for easy management
- Automatic cleanup of old backups
- Customizable backup settings
- Minimal configuration required
System Requirements
Ensure your system meets the minimum version requirements before installing this package.
- PHP Version: 8.2
- Laravel Version: 11
Installation
Step 1: Install the Package
Step 2: Publish Configuration
Local Backup Configuration
Backups are stored locally by default using the local
disk.
Usage
Run a Backup
To create a new backup, run the following Artisan command:
Clean Up Old Backups
- By default, old backups are automatically cleaned up after each backup.
- Backups older than 14 days are automatically deleted to free up space.
- This retention period is configurable, allowing you to adjust how long backups are kept based on your needs.
Disabling Automatic Cleanup
If you want to disable automatic cleanup, you can set the automatic
option to false
in the configuration file:
If you prefer to manually clean up old backups, you can run the following Artisan command:
Google Drive Integration
Step 1: Configure Google Drive
Add the following configuration to config/filesystems.php
:
NOTE: you can customize the disk name (e.g., google_db_backup
instead of google
)
Step 2: Environment Variables
Add these variables to your .env
file:
Google Drive API Setup Guide
This guide will walk you through setting up Google Drive API credentials and obtaining the necessary tokens for integration with your Laravel application.
Step 1: Create Google Cloud Project
- Visit Google Cloud Console
- Click "Select a project" β "New Project"
- Enter a project name and click "CREATE"
- Wait for the project to be created and select it
Step 2: Enable Google Drive API
- In the left sidebar, navigate to "APIs & Services" β "Library"
- Search for "Google Drive API"
- Click on "Google Drive API"
- Click "ENABLE"
Step 3: Configure OAuth Consent Screen
- Go to "APIs & Services" β "OAuth consent screen"
- Select "External" user type and click "CREATE"
- Fill in the required information:
- App name
- User support email
- Developer contact information
- Click "SAVE AND CONTINUE"
- Skip scopes screen by clicking "SAVE AND CONTINUE"
- Add test users (your email) if in testing mode
- Click "SAVE AND CONTINUE"
Step 4: Create Credentials
For Web Application:
- Go to "APIs & Services" β "Credentials"
- Click "+ CREATE CREDENTIALS" β "OAuth client ID"
- Select "Web application" as application type
- Enter a name for your client
-
Under "Authorized redirect URIs" add:
- Click "CREATE"
- A popup will show your Client ID and Client Secret
- Add them to your
.env
file asGOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
For Desktop Application:
- Go to "APIs & Services" β "Credentials"
- Click "+ CREATE CREDENTIALS" β "OAuth client ID"
- Select "Desktop app" as application type
- Enter a name for your client
- Click "CREATE"
- A popup will show your Client ID and Client Secret
- Add them to your
.env
file asGOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
Step 5: Get Refresh Token
For Web Application:
- Go to Google OAuth Playground
- Click the gear icon (βοΈ) in the top right corner
- Check "Use your own OAuth credentials"
- Enter your:
- OAuth Client ID
- OAuth Client Secret
- Click "Close"
- In the left sidebar, find "Drive API v3"
- Select
https://www.googleapis.com/auth/drive.file
- Click "Authorize APIs"
- Log in with your Google account and accept permissions
- Click "Exchange authorization code for tokens"
- Copy the refresh token from the response and add it to your
.env
file asGOOGLE_REFRESH_TOKEN
For Desktop Application:
- Open the following URL in your web browser (replace
YOUR_CLIENT_ID
with your actual client ID): https://accounts.google.com/o/oauth2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive.file&access_type=offline&prompt=consent- Using the scope
https://www.googleapis.com/auth/drive.file
allows your application to view and manage Google Drive files and folders that were opened or created by the app
- Using the scope
- Sign in with your Google account and grant access to the requested permissions
- Google will display an authorization code on the screen. Copy this code
-
In your terminal run the following
curl
command, to exchange the authorization code for tokens (replace YOUR_AUTHORIZATION_CODE, YOUR_CLIENT_ID, and YOUR_CLIENT_SECRET with the actual values): - The response will include a refresh token. Copy it and store it in your
.env
file asGOOGLE_REFRESH_TOKEN
Step 6: Get Google Drive Folder ID
- Go to Google Drive
- Create a new folder or select an existing one for backups
- Open the folder
- Copy the folder ID from the URL
- The URL will look like:
https://drive.google.com/drive/folders/1A2B3C4D5E6F7...
- The folder ID is the string after
/folders/
- The URL will look like:
- Add this folder ID to your
.env
file asGOOGLE_FOLDER_ID
That's it! π You're now ready to use this package β have fun and enjoy! ππ
Events
This package emits the following events that you can listen to in your application:
MarekMiklusek\DatabaseBackup\Events\BackupCreated
Triggered when a database backup is successfully created.
MarekMiklusek\DatabaseBackup\Events\BackupFailed
Triggered when a database backup fails.
Common Issues
- Redirect URI Mismatch: Make sure you've added the exact OAuth Playground URL to authorized redirect URIs
- Invalid Credentials: Double-check all IDs and tokens are copied correctly
- Token Expiration: Refresh tokens don't expire unless revoked, but if you create new credentials, you'll need a new refresh token
- Permission Issues: Ensure the Google Drive API is enabled and the correct scope is selected
Security Notes
- Keep all credentials secure and never commit them to version control
- Use environment variables for all sensitive information
- Consider implementing credential rotation for production environments
License
The MIT License (MIT). Please see License File for more information.