Skip to content

Instantly share code, notes, and snippets.

@alenbasic
Created June 21, 2014 08:18
Show Gist options
  • Save alenbasic/ac18751d62890e63f4f9 to your computer and use it in GitHub Desktop.
Save alenbasic/ac18751d62890e63f4f9 to your computer and use it in GitHub Desktop.
import dropbox
import time
import os
APP_KEY = ''
APP_SECRET = ''
ACCESS_TOKEN = ""
TIMESTAMP = time.strftime('%Y-%m-%d')
FILENAME = "filename.sql"
TAR_XZ = "filename_" + TIMESTAMP +".tar.xz"
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET)
client = dropbox.client.DropboxClient(ACCESS_TOKEN)
try:
os.popen("mysqldump -u username -pPASSWORD --single-transaction database_name > " + FILENAME)
os.popen("tar -jcf " + TAR_XZ + " " + FILENAME)
os.popen("rm " + FILENAME)
f = open(TAR_XZ, 'rb')
response = client.put_file('/folder/' + TAR_XZ, f)
f.close()
os.popen("rm " + TAR_XZ)
os.popen('echo "" | mail -s "Dropbox: Upload Successful" me@domain.com)
except Exception:
os.popen('echo "" | mail -s "Dropbox: Error. Please investigate." me@domain.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment