Skip to content

A simple tool to backup data & db from a web server to Google Drive.

Notifications You must be signed in to change notification settings

alexsoyes/php-google-drive-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

🎉

OAuth scopes in Google Cloud Console

Disclaimer

⚠️You should never trust a script found on GitHub to backup your data!

🔥 I made this script in a few hours. It not perfect, but it works very well.

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.
  • Activate Google Drive API.
    • Go to "OAuth authorization screen" and edit application.
    • Enable field .../auth/drive in order to create/remove some files. OAuth scopes in Google Cloud Console
  • Add a test user with the email you wish to use. Add a test user in Google Cloud Console
  • 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! ✅

Add a cronjob to start backing up in OVH

Developer resources 📝

About

A simple tool to backup data & db from a web server to Google Drive.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages