我是靠谱客的博主 儒雅猎豹,这篇文章主要介绍Python实现配置文件备份的方法,现在分享给大家,希望可以做个参考。

本文实例讲述了Python实现配置文件备份的方法。分享给大家供大家参考。具体如下:

这里平台为Linux:

#!/usr/bin/python
#Author:gdlinjianying@qq.com
import os
import time
source = ['/etc/sysconfig/network-scripts', '/etc/sysconfig/network', '/etc/resolv.conf']
target_dir = '/opt/'
target = target_dir + time.strftime('%Y%m%d%H%M%S' + '.tar.gz')
tar_command = "tar -czvf '%s' %s" % (target, ' '.join(source))
if os.system(tar_command) == 0:
  print '\nResult:'
  print 'Successful backup to', target
else:
  print '\nResult:'
  print 'Backup failed'

希望本文所述对大家的Python程序设计有所帮助。

最后

以上就是儒雅猎豹最近收集整理的关于Python实现配置文件备份的方法的全部内容,更多相关Python实现配置文件备份内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(233)

评论列表共有 0 条评论

立即
投稿
返回
顶部