Skip to content

Instantly share code, notes, and snippets.

@aidvu
Last active December 20, 2015 22:39
Show Gist options
  • Save aidvu/6206887 to your computer and use it in GitHub Desktop.
Save aidvu/6206887 to your computer and use it in GitHub Desktop.
Backup MySQL dump to Dropbox using Python API
[backup]
access_token: {token}
from_dir: {from_dir}
to_dir: {to_dir}
file_types: {file_types}
# Include the Dropbox SDK
import dropbox
# For the Config
import ConfigParser
# For file/folder traversal
import glob
import os
# Read the config
config = ConfigParser.ConfigParser()
config.read("config.ini")
# access_token needed for Dropbox API
access_token = config.get("backup", "access_token")
# Directory where the files are on the local disk
from_dir = config.get("backup", "from_dir")
# Where to copy in Dropbox
to_dir = config.get("backup", "to_dir")
# What file types to copy
file_types = config.get("backup", "file_types")
# Initialize Dropbox Client
client = dropbox.client.DropboxClient(access_token)
# Copy the weekly MySQL backups to DropBox
os.chdir(from_dir)
for files in glob.glob(file_types):
f = open(files)
response = client.put_file(to_dir + files, f, True)
print "uploaded: ", response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment