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-openCV读RGB通道图实例

我就废话不多说了,直接上代码吧! #coding=utf-8 '''openCV中最核心的的类是Mat,他是matrix的缩写代表矩阵,该类在头文件opencv2\core\core...

python 用 xlwings 库 生成图表的操作方法

xlwings是一个获得BSD许可的Python库,可以很容易地从Excel调用Python,反之亦然。 它适用于Windows和Mac上的Microsoft Excel。 在官方文档里...

Django+JS 实现点击头像即可更改头像的方法示例

Django+JS 实现点击头像即可更改头像的方法示例

首先,在models.py中创建UserModels类 from django.db import models from django.contrib.auth.models im...

python实现探测socket和web服务示例

操作系统:linux软件环境:Python 2.7.3 用法:复制代码 代码如下:$ ./MonSocket.py # This is check the URI or Socket...

python实现忽略大小写对字符串列表排序的方法

本文实例讲述了python实现忽略大小写对字符串列表排序的方法,是非常实用的技巧。分享给大家供大家参考。具体分析如下: 先来看看如下代码: string = ''' the stir...