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

yipeiwu_com6年前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 如何优雅的将数字转化为时间格式的方法

将数字转化成时间格式 from dateutil.parser import parse a=20170825 b=str(a) c=parse(b) print(c) 20...

Python requests模块实例用法

1、Requests模块说明 Requests 是使用 Apache2 Licensed 许可证的 HTTP 库。用 Python 编写,真正的为人类着想。 Python 标准库中的 u...

python中常用的九种预处理方法分享

python中常用的九种预处理方法分享

本文总结的是我们大家在python中常见的数据预处理方法,以下通过sklearn的preprocessing模块来介绍; 1. 标准化(Standardization or Mean R...

python定时检查某个进程是否已经关闭的方法

本文实例讲述了python定时检查某个进程是否已经关闭的方法。分享给大家供大家参考。具体如下: import threading import time import os impo...

python3.5基于TCP实现文件传输

本文实例为大家分享了python3.5基于TCP实现文件传输的具体代码,供大家参考,具体内容如下 服务器代码 # _*_ coding:utf-8 _*_ from socket...