Last active
December 20, 2015 22:39
-
-
Save aidvu/6206887 to your computer and use it in GitHub Desktop.
Backup MySQL dump to Dropbox using Python API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[backup] | |
access_token: {token} | |
from_dir: {from_dir} | |
to_dir: {to_dir} | |
file_types: {file_types} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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