首页 > 代码库 > 备份文件
备份文件
学习OS模块:
#!/usr/bin/pythonimport osimport timeimport socketdef getsource(): print "[Info]-Please input the absolute path of file or directory which you want to back up." spath = raw_input(‘>‘) if not os.path.exists(spath): print "[Error]-%s does not exsist.Try again."%spath exit() return spathdef gettarget(): print "[Info]-Please input the absolute path of target directory." tpath = raw_input(‘>‘) if not os.path.exists(tpath): os.makedirs(tpath) return tpathdef backup(spath,tpath): hostname = socket.gethostname() filename = ‘_‘.join([hostname,time.strftime(‘%m-%d-%Y‘),‘logs.tar.gz‘]) filepath = tpath + os.sep + filename clist = [‘tar -zcvf‘, filepath, spath] command = ‘ ‘.join(clist) os.system(command) print "Backup successfully!"if __name__ == ‘__main__‘: source = getsource() target = gettarget() backup(source,target)
备份文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。