This script backs up files from a local directory to a specific folder in your Google Drive using the Google Drive API v3.
-
Google Cloud Console:
- Create a project at Google Cloud Console.
- Enable the Google Drive API.
- Go to OAuth consent screen, set User Type to 'External', and add your email as a test user.
- Go to Credentials, click 'Create Credentials' -> 'OAuth client ID'.
- Select 'Desktop app', name it, and download the JSON file.
- Rename the downloaded file to
credentials.jsonand place it in this project folder.
-
Installation:
pip install -r requirements.txt
- Place files you want to back up inside a folder named
backup_files(created automatically on first run). - Run the script:
python sync.py
- The first time you run it, a browser window will open for authentication. A
token.jsonfile will be created to store your session.
- Automatically creates the destination folder on Drive.
- Checks if files already exist: updates existing files or uploads new ones.