This Python script allows you to backup all files in a local folder to a specific folder on your Google Drive. It compares the timestamps of the local files with the ones on Google Drive and uploads/downloads the files accordingly to keep them in sync.
- Automatically uploads new or modified files from the local folder to the Google Drive folder.
- Downloads updated files from Google Drive to the local folder if they are newer than the local version.
- Compares file timestamps to avoid unnecessary uploads/downloads.
- A Google account with access to Google Drive.
- Python 3.6 or later installed on your local machine.
- Clone or download this repository to your local machine.
- Go to the Google API Console and create a new project.
- Enable the Google Drive API for your project.
- Create new OAuth 2.0 credentials:
- Click on "Create credentials" and select "OAuth client ID".
- Select "Desktop app" as the Application type.
- Enter a name for your credentials (e.g., "Backup Files to Google Drive").
- Click "Create" and download the credentials JSON file.
- Move the downloaded credentials JSON file to the same directory as the script and rename it to
credentials.json
. - Open the script in a text editor and replace the following variables with your own values:
SAVE_FOLDER_PATH
: The local folder path you want to backup (e.g.,C:\\Users\\username\\Documents\\MyBackupFolder\\
).YOUR_FOLDER_ID
: The ID of the folder in Google Drive where you want to backup your files. You can find the folder ID in the URL when you open the folder in Google Drive (e.g.,https://drive.google.com/drive/folders/1AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPp
).
- Install the required Python packages:
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
- Run the script:
python backup_files_to_google_drive.py
- On the first run, a browser window will open asking you to authorize the application to access your Google Drive. Log in with your Google account and grant the requested permissions. The script will create a
token.json
file to store your access and refresh tokens so that you don't need to authorize the application again the next time you run it. - The script will now start syncing the files between your local folder and the Google Drive folder.
Please feel free to submit issues or pull requests if you encounter any problems or have suggestions for improvements.
This project is licensed under the MIT License. See the LICENSE file for details.