- Timestamp:
- Jul 25, 2016, 1:55:19 PM (3 years ago)
- Location:
- n4d-nfs/trunk/fuentes/install
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
n4d-nfs/trunk/fuentes/install/etc/n4d/conf.d/NfsManager
r1152 r2264 10 10 clean_exports_file=adm,admins 11 11 remove_mount_on_boot=adm,admins 12 backup=adm,admins 13 restore=adm,admins -
n4d-nfs/trunk/fuentes/install/usr/share/n4d/python-plugins/NfsManager.py
r1184 r2264 21 21 self.tpl_env = Environment(loader=FileSystemLoader('/usr/share/n4d/templates/nfs')) 22 22 23 self.backup_files=[r'/lib/systemd/system/net-server\x2dsync.mount'] 24 self.backup_dirs=["/etc/exports.d/"] 25 23 26 # LLX TESTING 24 27 #self.nfs_file="/tmp/exports" … … 54 57 info=info.strip("\n") 55 58 info=info.split("(") 56 ip=info[0]59 p=info[0] 57 60 options=info[1].strip(")") 58 61 … … 91 94 exports=self.parse_exports_file() 92 95 93 print 194 95 96 if d not in exports: 96 97 exports[d]={} 97 print 298 98 exports[d][ip]=options 99 99 return self.write_exports_file(exports) … … 217 217 218 218 return {"status":True,"msg":"NfsManager exports.d file is now clean"} 219 219 220 def makedir(self,dir_path=None): 221 222 if not os.path.isdir(dir_path): 223 os.makedirs(dir_path) 224 225 return [True] 226 227 def backup(self,dir_path="/backup"): 228 try: 229 self.makedir(dir_path) 230 231 #get_backup_name es una funcion que esta definida en n4d 232 file_path=dir_path+"/"+get_backup_name("NfsManager") 233 234 tar=tarfile.open(file_path,"w:gz") 235 for f in self.backup_files: 236 if os.path.exists(f): 237 tar.add(f) 238 for d in self.backup_dirs: 239 if os.path.exists(d): 240 for f in os.listdir(d): 241 tar.add(d+f) 242 243 tar.close() 244 print "Backup generated in %s" % file_path 245 return [True,file_path] 246 247 248 except Exception as e: 249 print "Backup failed", e 250 return [False,str(e)] 251 252 #def backup 253 254 255 def restore(self,file_path=None): 256 257 #Ordeno de manera alfabetica el directorio y busco el fichero que tiene mi cadena 258 if file_path==None: 259 dir_path="/backup" 260 for f in sorted(os.listdir(dir_path),reverse=True): 261 262 if "NfsManager" in f: 263 file_path=dir_path+"/"+f 264 break 265 266 #Descomprimo el fichero y solo las cadenas que espero encontrar son las que restauro, reiniciando el servicio 267 268 269 try: 270 if os.path.exists(file_path): 271 272 tmp_dir=tempfile.mkdtemp() 273 tar=tarfile.open(file_path) 274 tar.extractall(tmp_dir) 275 tar.close 276 277 for f in self.backup_files: 278 tmp_path=tmp_dir+f 279 if os.path.exists(tmp_path): 280 shutil.copy(tmp_path,f) 281 282 283 for d in self.backup_dirs: 284 tmp_path=tmp_dir+d 285 if os.path.exists(tmp_path): 286 cmd="cp -r " + tmp_path + "/* " + d 287 if not os.path.exists(d): 288 os.makedirs(d) 289 os.system(cmd) 290 291 292 print "File is restored in %s" % self.backup_files 293 294 return [True,""] 295 296 297 except Exception as e: 298 299 print "Restored failed", e 300 return [False,str(e)] 301 302 pass 303 304 #def restore 220 305 221 306
Note: See TracChangeset
for help on using the changeset viewer.