-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.py
More file actions
executable file
·44 lines (37 loc) · 1.47 KB
/
backup.py
File metadata and controls
executable file
·44 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
sys.path.insert(0,"C:/Users/kaixtr/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0/LocalCache/local-packages/Python310/site-packages")
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
import secret
BPATH = '/backuptest.db'
print('Hello World!')
f = open('backuptest.db','w')
f.write('This is a file uploaded to Dropbox.')
f.close()
def upload(file):
with open(file, 'rb') as f:
try: dbx.files_upload(f.read(), BPATH, mode=WriteMode('overwrite'))
except ApiError as err:
if (err.error.is_path() and err.error.get_path().reason.is_insufficient_space()):
print("ERROR: OUT OF SPACE IN STORAGE.")
elif err.user_message_text: print(err.user_message_text)
else: print(err)
def download(file,rev=None):
dbx.files_restore(BPATH, rev)
dbx.files_download_to_file(file, BPATH, rev)
def select_revision():
entries = dbx.files_list_revisions(BACKUPPATH, limit=30).entries
revisions = sorted(entries, key=lambda entry: entry.server_modified)
for revision in revisions:
print(revision.rev, revision.server_modified)
return revisions[0].rev
if __name__ == '__main__':
if (len(secret.DROPBOX_ACCESS_TOKEN) == 0): print("ERROR: ACCESS_TOKEN NOT FOUND")
with dropbox.Dropbox(secret.DROPBOX_ACCESS_TOKEN) as dbx:
try:
user = dbx.users_get_current_account()
print('uploading...')
upload('backuptest.db')
#download(select_revision())
except AuthError: print("ERROR: INVALID ACCESS_TOKEN")