-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecover.py
executable file
·93 lines (66 loc) · 2.11 KB
/
recover.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python2
import config
import header
import cgi,commands,os,MySQLdb
db = MySQLdb.connect("localhost","root", "Aj1.....", "arcus")
cursor = db.cursor()
user_id = header.cookie_value()
# get username
sql = "SELECT * FROM users WHERE id={0}". format(user_id)
try:
cursor.execute(sql)
results = cursor.fetchone()
userName = results[1]
except:
print "Error: unable to fecth data"
snap_name = cgi.FormContent()['n'][0]
nfs_id = cgi.FormContent()['id'][0]
# get nfs storage information
sql = "SELECT * FROM nfs WHERE id={0}". format(nfs_id)
try:
cursor.execute(sql)
results = cursor.fetchone()
except:
print "Error: unable to fecth data"
exportsFp = open("/Arcus/public/tmp/nfs/exports", "a")
exportsFp.write("/nfs-share/recover-{0} {1}(rw,no_root_squash)\n". format(nfs_id, results[3]))
exportsFp.close()
ansibleString = """
#software install
- hosts: web
tasks:
- package:
name: "nfs-utils"
state: present
- name: Permanently mount LV
mount:
path: /nfs-share/recover-{0}
src: /dev/vg1/{1}
fstype: ext4
state: mounted
- name: "setup config file"
copy:
src: "/Arcus/public/tmp/nfs/exports"
dest: "/etc/exports"
#systemctl restart nfs
- service:
name: "nfs"
state: restarted
""". format(nfs_id, snap_name)
ansibleProg = open("/Arcus/public/tmp/nfs/nfs.ymal", "w")
ansibleProg.write(ansibleString)
ansibleProg.close()
ansF = commands.getstatusoutput("sudo ansible-playbook /Arcus/public/tmp/nfs/nfs.ymal")
if(ansF[0] == 0):
# set up client
dirF = commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sudo mkdir -p /media/recover-{2}". format(results[4], results[3], nfs_id))
mountF = commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sudo mount 192.168.43.171:/nfs-share/recover-{2} /media/recover-{2}". format(results[4], results[3], nfs_id))
if(mountF[0] == 0):
header.header_content()
print("<h2> Successfully Recovered</h2>")
else:
header.header_content()
print(mountF[1])
else:
header.header_content()
print("<pre> " + ansF[1] + " </pre>")