Seamlessly Migrating from Dropbox to Google Drive: A Step-by-Step Automation Guide
As businesses grow and team dynamics evolve, file storage needs often change too. When your organization decides to shift from Dropbox to Google Drive, it’s more than just moving files—it’s about ensuring smooth collaboration within the Google ecosystem. However, migrating hundreds or thousands of files manually is inefficient, prone to errors, and risks disrupting daily workflows.
Most guides you’ll find either rely on manual drag-and-drop or recommend third-party apps that may expose sensitive data or add extra costs. In this post, I’ll walk you through building a custom automated migration pipeline that safely moves your Dropbox content into Google Drive, preserving metadata, permissions, and minimizing downtime.
Why Automate Dropbox to Google Drive Migration?
Before diving into the steps, let’s nail down why automation matters:
- Preserve Metadata and Permissions: Manual transfers usually lose timestamps, sharing settings, and version history.
- Minimize Downtime: Automation cuts the window when files are inaccessible or workflows are interrupted.
- Security: Avoid third-party apps that store your enterprise data externally.
- Repeatability: Perfect for large or ongoing migrations with incremental syncs.
Tools and APIs You’ll Need
- Dropbox API: To list, download, and extract file metadata from your Dropbox.
- Google Drive API: To upload files, set metadata, and manage permissions in Drive.
- Python: A great scripting language for building your migration pipeline.
- OAuth 2.0 Credentials: For securely authenticating to both Dropbox and Google Drive APIs.
Step 1: Setup API Access for Both Platforms
Dropbox
- Go to Dropbox App Console.
- Create a new app with “Full Dropbox” access.
- Generate an OAuth token—store this securely.
Google Drive
- Visit Google Cloud Console.
- Create a new project and enable the Google Drive API.
- Configure OAuth consent and generate credentials (OAuth client ID).
- Download the
credentials.json
file.
Step 2: Authenticate and Connect
Using Python, install required packages:
pip install dropbox google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
Authenticate Dropbox with its token:
import dropbox
DROPBOX_ACCESS_TOKEN = 'YOUR_DROPBOX_ACCESS_TOKEN'
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
Authenticate Google Drive using OAuth:
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
import pickle
import os
SCOPES = ['https://www.googleapis.com/auth/drive']
def google_drive_auth():
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
return build('drive', 'v3', credentials=creds)
drive_service = google_drive_auth()
Step 3: List Dropbox Files with Metadata
To migrate files properly, you need to fetch metadata such as file paths, modified dates, and sharing info.
def list_dropbox_files(path=''):
files = []
result = dbx.files_list_folder(path, recursive=True)
while True:
for entry in result.entries:
if isinstance(entry, dropbox.files.FileMetadata):
files.append(entry)
if result.has_more:
result = dbx.files_list_folder_continue(result.cursor)
else:
break
return files
files_to_migrate = list_dropbox_files()
print(f"Found {len(files_to_migrate)} files in Dropbox.")
Step 4: Download Dropbox Files Temporarily
The simplest approach is downloading each file to your local environment (or a temporary cloud VM) before uploading to Google Drive.
import io
def download_dropbox_file(file_metadata):
metadata, res = dbx.files_download(file_metadata.path_lower)
return io.BytesIO(res.content)
# Example: download first file
file_stream = download_dropbox_file(files_to_migrate[0])
Step 5: Upload Files to Google Drive, Preserving Metadata
When uploading:
- Create folders matching Dropbox paths if they don’t exist.
- Preserve modified dates using the
modifiedTime
property. - (Optional) Use Google Drive permissions API to replicate sharing.
Here’s an example to create folders and upload a file:
def create_drive_folder(name, parent_id=None):
file_metadata = {
'name': name,
'mimeType': 'application/vnd.google-apps.folder',
}
if parent_id:
file_metadata['parents'] = [parent_id]
folder = drive_service.files().create(body=file_metadata, fields='id').execute()
return folder.get('id')
def find_or_create_folder(path):
folders = path.strip('/').split('/')
parent_id = None
for folder in folders:
# Search if folder exists under current parent
query = f"name='{folder}' and mimeType='application/vnd.google-apps.folder'"
if parent_id:
query += f" and '{parent_id}' in parents"
results = drive_service.files().list(q=query, spaces='drive', fields='files(id, name)').execute()
files = results.get('files', [])
if files:
parent_id = files[0]['id']
else:
parent_id = create_drive_folder(folder, parent_id)
return parent_id
def upload_file_to_drive(file_metadata, file_stream):
# Extract folder path and file name from Dropbox path
import os
dropbox_path = file_metadata.path_lower
folder_path, file_name = os.path.split(dropbox_path)
drive_folder_id = find_or_create_folder(folder_path)
media_body = file_stream
file_metadata_drive = {
'name': file_name,
'parents': [drive_folder_id],
'modifiedTime': file_metadata.client_modified.isoformat() + 'Z'
}
media = googleapiclient.http.MediaIoBaseUpload(media_body, mimetype='application/octet-stream')
uploaded_file = drive_service.files().create(body=file_metadata_drive, media_body=media, fields='id').execute()
print(f"Uploaded {file_name} to Google Drive.")
return uploaded_file.get('id')
# Usage example:
file_stream = download_dropbox_file(files_to_migrate[0])
upload_file_to_drive(files_to_migrate[0], file_stream)
Step 6: (Optional) Recreate Sharing Permissions
Dropbox and Google Drive handle permissions differently, but you can approximate by:
- Listing shared members on Dropbox via API.
- Adding same users with equivalent permissions in Google Drive.
Due to complexity, handle this once file data is safely migrated.
Step 7: Automate and Monitor
Package all these steps into a loop that processes files incrementally, includes error handling, and logs progress. This ensures any failures can be retried without starting over.
Example pseudocode:
for file_metadata in files_to_migrate:
try:
file_stream = download_dropbox_file(file_metadata)
upload_file_to_drive(file_metadata, file_stream)
except Exception as e:
print(f"Failed migrating {file_metadata.path_lower}: {e}")
Bonus Tips for a Smooth Migration
- Test on a small folder first before migrating everything.
- Backup important data before running your script.
- Use Google Drive’s "Team Drives" (Shared Drives) if your team uses G Suite/Google Workspace.
- Communicate with your team about migration timings to avoid file conflicts.
- Monitor Google Drive storage quotas.
Conclusion
Switching from Dropbox to Google Drive doesn’t have to be a headache filled with manual hassles and security compromises. With this step-by-step automation guide, you can build a secure, metadata-preserving, and efficient pipeline that moves your files quickly and safely—keeping your team productive and centered within the Google ecosystem.
Ready to make the jump? Start setting up your APIs and try migrating a few files now! If you have questions or want me to share a full GitHub repo, drop a comment below.
Happy migrating! 🚀