Last active
March 14, 2020 00:49
-
-
Save scturtle/41d9aca1f192354adaccde0b67dbb334 to your computer and use it in GitHub Desktop.
script to backup file to dropbox
This file contains 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
!/usr/bin/bash | |
DROPBOX_KEY='XXXXXX' | |
FILENAME=XXXXXX | |
cd XXXXXX | |
tar czf $FILENAME XXXXXX > /dev/null | |
/usr/bin/python - <<END | |
import dropbox | |
from dropbox.files import WriteMode | |
from os.path import getsize, basename | |
dbx = dropbox.Dropbox('$DROPBOX_KEY') | |
CHUNK_SIZE = 20 * 1024 * 1024 | |
f = open('$FILENAME', 'rb') | |
file_size = getsize('$FILENAME') | |
result = dbx.files_upload_session_start(f.read(CHUNK_SIZE)) | |
cursor = dropbox.files.UploadSessionCursor(session_id=result.session_id, offset=f.tell()) | |
dbx_path = '/backup/' + basename('$FILENAME') | |
commit = dropbox.files.CommitInfo(path=dbx_path, mode=WriteMode.overwrite) | |
while f.tell() <= file_size: | |
if file_size - f.tell() <= CHUNK_SIZE: | |
dbx.files_upload_session_finish(f.read(CHUNK_SIZE), cursor, commit) | |
break | |
else: | |
dbx.files_upload_session_append_v2(f.read(CHUNK_SIZE), cursor) | |
cursor.offset = f.tell() | |
f.close() | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment