-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.py
More file actions
executable file
·47 lines (38 loc) · 1.12 KB
/
backup.py
File metadata and controls
executable file
·47 lines (38 loc) · 1.12 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
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
backup.py - backup dotfiles
usage:
backup.py
"""
import platform
from docopt import docopt
import sys
import os
from shutil import copyfile
from os.path import join as pj
import conf
def exitUnexistNode(nodeName, batches):
print("{} not found in batches. availiable: {}."
.format(node, ", ".join(batches)))
sys.exit(0)
if __name__ == "__main__":
batches = conf.batches
args = docopt(__doc__, version="1.0")
node = platform.node()
print('going to backup {}'.format(node) )
if node not in batches.keys():
exitUnexistNode(node, batches.keys())
os.makedirs(node, exist_ok=True)
for flname in batches[node]['files']:
expanded = os.path.expanduser(flname)
flname = flname.split('/', 1)[1]
d = pj(node, os.path.dirname(flname))
if not os.path.exists(d):
os.makedirs(d)
src, dst = expanded, pj(node, flname)
print("backup {} to {}".format(src, dst))
if not os.path.exists(src):
print(f"{src} doesn't exists")
else:
copyfile(src, dst)