您的位置:首页 > 编程语言 > Python开发

Python实现配置文件备份的方法

2015-07-30 00:00 1051 查看

本文实例讲述了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程序设计有所帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: