forked from nckz/BackupHub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tarmd5.py
executable file
·47 lines (39 loc) · 1.23 KB
/
tarmd5.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
#!/usr/bin/env python
# Author: Nick Zwart
# Date: 2016dec09
# Brief: This script runs tar on the given file or directory then runs md5sum
# on the resulting tar.
md5sum = '/opt/local/bin/gmd5sum'
tar = '/usr/bin/tar'
nice = '/usr/bin/nice'
time = '/usr/bin/time'
rm = '/bin/rm'
import os
import sys
import subprocess as sp
if len(sys.argv) != 2:
print("USAGE: %s <path>" % sys.argv[0])
print("Output: <path>.tar <path>.tar.md5sum")
sys.exit(1)
# input params
path = sys.argv[1]
output_tar = path+'.tar'
output_md5 = output_tar+'.md5'
# print usage if needed
if not os.path.exists(path):
print("Invalid Path: %s" % path)
sys.exit(1)
def check_output(fn):
if os.path.exists(fn):
print("Output File Already Exists: %s" % fn)
print("Removing File...")
sp.check_call("%s -v %s" % (rm, fn), shell=True)
# delete target files if they exist
check_output(output_tar)
check_output(output_md5)
# perform tar and md5sum
if os.path.exists(path):
print("Performing TAR on %s..." % path)
sp.check_call("%s %s -n 19 %s cvf %s %s" % (time, nice, tar, output_tar, path), shell=True)
print("Performing MD5SUM on %s..." % output_tar)
sp.check_call("%s %s > %s" % (md5sum, output_tar, output_md5), shell=True)