这里平台为Linux:
#!/usr/bin/python #Author:gdlinjianying@qq测试数据 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实现配置文件备份的方法的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did91676