def dropbox_mkdir(): dropbox_access_token = session.get(DROPBOX_ACCESS_KEY, None) if dropbox_access_token is None: return "please log into dropbox first" dropbox_client = get_client(dropbox_access_token) directory = request.form.get('path', None) if directory is None: return "You didn't specify a path" try: dropbox_client.file_create_folder(directory) return directory except Exception, e: return e.message
database_archive = "database-backup-" + date.today().strftime("%m-%d-%Y") mysqldump_cmd = ( "mysqldump -u" + MYSQL_USERNAME + ' -p"' + MYSQL_PASSWORD + '" --opt --flush-logs --all-databases | gzip > /home/mruschak/DatabaseDumps/sql-' + database_archive + ".gzip" ) subprocess.call(mysqldump_cmd, shell=True) subprocess.call("/bin/tar czf /tmp/" + backup_archive + " /home", shell=True) client.file_create_folder(hostname) backup_file = open("/tmp/" + backup_archive, "rb") backup_file_bytes = os.path.getsize("/tmp/" + backup_archive) uploader = client.get_chunked_uploader(backup_file, backup_file_bytes) while uploader.offset < backup_file_bytes: try: upload = uploader.upload_chunked() except rest.ErrorResponse, e: print "Error occurred. Please try again." uploader.finish(hostname + "/" + backup_archive) subprocess.call("rm /tmp/" + backup_archive, shell=True)
#Now create a dictionary containing the file name, and it's size if os.path.lexists(SYNC_DIR): for file in os.listdir(SYNC_DIR): SYNC_DIR_LIST[file] = os.path.getsize(SYNC_DIR + '/' + file) #Get the same from your dropbox if DEST_DIR in client.metadata('/')['contents'][0]['path']: SYNC_DIR_META = client.metadata(DEST_DIR) print 'Destination directory already exists' else: client.file_create_folder(DEST_DIR) SYNC_DIR_META = client.metadata(DEST_DIR) print 'Just created the destination directory' SYNC_DIR_META_LIST = {} #Create a dictionary with the same info as SYNC_DIR_LIST for file in SYNC_DIR_META['contents']: SYNC_DIR_META_LIST[os.path.split(file['path'])[1]] = file['bytes'] #Copy only if file does not exist on Dropbox, or size different from source(modified file) or does not start with . (hidden files) for file in SYNC_DIR_LIST: if (file[0] != '.'): if (file not in SYNC_DIR_META_LIST): client.put_file(DEST_DIR + '/' + file,open(SYNC_DIR + '/' + file)) print 'Copying ' + file + ' to Dropbox' if (file in SYNC_DIR_META_LIST) and (SYNC_DIR_META_LIST[file] != SYNC_DIR_LIST[file]):