-
Notifications
You must be signed in to change notification settings - Fork 18
/
sync.py
60 lines (53 loc) · 1.26 KB
/
sync.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import glob
import logging
import os
import rclone
cfg_path = "./rclone.conf"
from_drives = [
"test",
"___backups",
"__code",
"__meow",
"__quack",
"dumpyard",
"pss",
"public",
]
to_drives = [
"1",
"2",
"3",
"4",
"5",
]
cfg = open(cfg_path).read()
rc = rclone.with_config(cfg)
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(name)s [%(levelname)s]: %(message)s")
flags = ["--drive-server-side-across-configs"]
if os.path.isdir("accounts"):
sa_files = glob.glob("accounts/*.json")
assert len(sa_files)
flags.append("--drive-service-account-file-path")
flags.append("accounts")
to_drive = to_drives[0]
for from_drive in from_drives:
print(f"From: {from_drive}:")
print(f"To: {to_drive}:sync/{from_drive}")
result = rc.sync(
f"{from_drive}:",
f"{to_drive}:sync/{from_drive}",
flags,
)
if "error" in result["error"].decode("utf-8").lower():
exit(1)
from_drive = to_drives[0]
for to_drive in to_drives[1:]:
print(f"From: {from_drive}:sync/")
print(f"To: {to_drive}:sync/")
result = rc.sync(
f"{from_drive}:sync/",
f"{to_drive}:sync/",
flags,
)
if "error" in result["error"].decode("utf-8").lower():
exit(1)