-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.py
executable file
·46 lines (31 loc) · 952 Bytes
/
backup.py
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
45
46
#!/usr/bin/python3
# Backs up the minecraft world settings to dropbox
import os
import config as c
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
config = c.load_config()
#TODO: make a mechanism to configure all this for future scripts
basepath = config["root_directory"]
filenames = ["world", "server.properties", "ops.json"]
zipname = config["server-name"] + ".zip"
TOKEN = config["dropbox-token"]
def backup(local, remote):
f = open(local, 'rb')
try:
dbx.files_upload(f.read(), remote, mode=WriteMode('overwrite'))
except ApiError as err:
print (err.user_message_text)
dbx = dropbox.Dropbox(TOKEN)
try:
dbx.users_get_current_account()
except AuthError as err:
exit("Invalid token")
# compress world
os.chdir(basepath)
cmd = "zip -r %s "%zipname
for filename in filenames:
cmd += " " + filename
os.system(cmd)
backup(zipname, "/"+zipname)