Révision 49 msc/timemachine/mount_tm_fugue
mount_tm_fugue (revision 49) | ||
---|---|---|
2 | 2 |
import os |
3 | 3 |
import subprocess |
4 | 4 |
import sys |
5 |
import time |
|
5 | 6 |
|
6 | 7 |
username = 'tjiang' |
8 |
work_tm = 'TM_FUGUE' |
|
9 |
home_tm = '' |
|
10 |
print 'begin mounting tm process' |
|
7 | 11 |
proc = subprocess.Popen("/sbin/ifconfig|grep inet",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
8 | 12 |
out,err = proc.communicate() |
13 |
if not err: |
|
14 |
print 'ipout',out |
|
15 |
else: |
|
16 |
print 'iperr',err |
|
9 | 17 |
for l in out.split('\n'): |
10 | 18 |
if "140.77.2" in l: |
11 | 19 |
ip = l.split()[1] |
... | ... | |
13 | 21 |
break |
14 | 22 |
else: |
15 | 23 |
in_ens = False |
24 |
proc = subprocess.Popen("sudo tmutil status",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
25 |
out,err = proc.communicate() |
|
16 | 26 |
|
17 |
if in_ens: |
|
18 |
proc = subprocess.Popen("/sbin/mount|grep TM_FUGUE",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
27 |
print 'in_ens',in_ens |
|
28 |
if in_ens and len(out.split('\n')) == 7: |
|
29 |
proc = subprocess.Popen("/sbin/mount|grep "+work_tm,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
19 | 30 |
out,err = proc.communicate() |
20 | 31 |
print 'mount returncode:', proc.returncode |
21 | 32 |
if proc.returncode: |
22 | 33 |
proc1 = subprocess.Popen("/usr/local/bin/sshfs "+username+"@fugue:/data/users/"+username+"/ /Users/"+username+"/fugue",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
23 | 34 |
out1,err1 = proc1.communicate() |
35 |
if err1: |
|
36 |
subprocess.Popen("/sbin/umount /Users/"+username+"/fugue",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
37 |
proc1 = subprocess.Popen("/usr/local/bin/sshfs "+username+"@fugue:/data/users/"+username+"/ /Users/"+username+"/fugue",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
38 |
out1,err1 = proc1.communicate() |
|
39 |
if err1: |
|
40 |
print err1 |
|
41 |
|
|
24 | 42 |
proc2 = subprocess.Popen("/usr/bin/hdiutil attach -mountpoint /Volumes/TM_FUGUE /$HOME/fugue/timemachine/TimeMachine.sparsebundle",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
25 | 43 |
out2,err2 = proc2.communicate() |
44 |
proc = subprocess.Popen("sudo tmutil enable",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
45 |
out,err = proc.communicate() |
|
46 |
proc = subprocess.Popen("sudo tmutil startbackup",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
47 |
out,err = proc.communicate() |
|
48 |
#wait until the backup is done |
|
49 |
while 1: |
|
50 |
time.sleep(10) |
|
51 |
proc = subprocess.Popen("sudo tmutil latestbackup",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
52 |
out,err = proc.communicate() |
|
53 |
now = [int(i) for i in time.strftime("%Y,%m,%d,%H%M%S").split(',')] |
|
54 |
lastbackup=[int(i) for i in out.split('/')[-1][:-1].split('-')] |
|
55 |
if now[:-1] == lastbackup[:-1] and now[-1] - lastbackup[-1] < 13: |
|
56 |
break |
|
57 |
|
|
58 |
proc = subprocess.Popen("sudo tmutil disable",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
59 |
out,err = proc.communicate() |
|
60 |
|
|
61 |
|
|
26 | 62 |
#proc3 = subprocess.Popen("/usr/bin/tmutil destinationinfo",shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
27 | 63 |
#out3,err3 = proc3.communicate() |
28 | 64 |
#for l in out3.split('\n'): |
Formats disponibles : Unified diff