-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup
More file actions
executable file
·49 lines (42 loc) · 1.43 KB
/
Copy pathbackup
File metadata and controls
executable file
·49 lines (42 loc) · 1.43 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
48
49
#!/usr/bin/env python2
# vi: ft=python
import argparse
import datetime
import time
import os
import shutil
def main():
"""docstring for main"""
parser = argparse.ArgumentParser(description='Backups a directory/file')
parser.add_argument('-d', '--delete',
action='store_true',
help='Move the file instead of copying it')
parser.add_argument('-p', '--pwd',
action='store_true',
help='Backup dest folder is pwd')
parser.add_argument('-n', '--dry',
action='store_true',
help='Dry run mode')
parser.add_argument('-v', '--verbose',
action='count',
help='Increase verbosity')
args, files = parser.parse_known_args()
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%dT%H%M%S')
for fyle in files:
path = os.path.abspath(fyle)
dest = path
if args.pwd:
dest = os.path.basename(os.path.abspath(fyle))
dest = "{}.{}".format(dest, ts)
if args.delete:
if args.verbose:
print "mv", path, dest
if not args.dry:
os.rename(path, dest)
else:
if args.verbose:
print "cp", path, dest
if not args.dry:
shutil.copytree(path, dest)
if __name__ == '__main__':
main()