PHP Google Drive backup
A (very) simple CLI tool that I used to backup my www directory and my database from OVH to Google Drive, in a cronjob.
Disclaimer
🔧
Getting started You need to configure your Google Cloud Console account first.
- Create a new project and an OAuth from quickstart.
- Download the
credentials.json
. - Upload it in the root directory of this project.
- Download the
- Activate Google Drive API.
- Add a test user with the email you wish to use.
-
❌ Do not activate the "production review" since:- You do not need it.
- It will make you unable to continue the process.
- Run the project using CLI (locally if you have to).
- Then, generate the proper
token.json
file by logging with the given URL from CLI.- Authenticate yourself with your Google Account...
- All good!
✅
🚀
Environments variables The following environment variables must be declared.
If you do not know how it works, just create a file named .env
in the root directory with your own configuration.
(The .env.dist
file contains a skeleton.)
Example:
DB_HOST=127.0.0.1
DB_USER=username
DB_PASSWORD=password
DB_NAME=database_name
DB_PORT=3306
DIRECTORY_TO_BACKUP=www
DELETE_UPLOADED_BACKUPS=false
ONLY_CLI=false
Feel free to fill it with your config!
Launching cronjob from OVH to Google Drive
Here is my cronjob configuration.
- I decided to run the job the first and the fifteenth of each month:
0 0 1,15 * *
- Logs are sent by email
- All good!
✅
📝
Developer resources - Google Quickstart with Google Drive API in PHP.
- Documentation & examples googleapis/google-api-php-client (used by this project).
- API documentation (for old school developers
💪 ).
- API documentation (for old school developers