`
canofy
  • 浏览: 820995 次
  • 性别: Icon_minigender_1
  • 来自: 北京、四川
社区版块
存档分类
最新评论

python备份文件

阅读更多
#-*-coding:utf-8-*-
import os
import time
#备份文件
# 1. The files and directories to be backed up are specified in a list.
source = ['/usr/local/apache2', '/usr/local/backup']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that

# 2. The backup must be stored in a main backup directory
target_dir = '/usr/local/qs/' # Remember to change this to what you will be using

# 3. The files are backed up into a zip file.
# 4. The current day is the name of the subdirectory in the main directory
today = target_dir + time.strftime('%Y%m%d')
# The current time is the name of the zip archive
now = time.strftime('%H%M%S')

# Take a comment from the user to create the name of the zip file
comment = raw_input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
    target = today + os.sep + now + '.zip'
else:
    target = today + os.sep + now + '_' + \
        comment.replace(' ', '_') + '.zip'
    # Notice the backslash!

# Create the subdirectory if it isn't already there
if not os.path.exists(today):
    os.mkdir(today) # make directory
    print 'Successfully created directory', today

# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))

# Run the backup
if os.system(zip_command) == 0:
    print 'Successful backup to', target
else:
    print 'Backup FAILED'
分享到:
评论

相关推荐

    Python特定文件备份方法源码

    Python备份文件的方法有很多种,和大家分享的这种方法是针对特定的文件类型来用python方法完成备份。简单的来理解就是:我们只对某个特定后缀名的文件进行检测及备份;在for file in files 循环的内部加一个适当的...

    python定时备份文件

    python定时压缩备份文件 定时器+os.system方法调用zip命令

    python-备份文件

    该脚本是用python编写,用于对每日文件进行压缩备份存放,适用于初学者,望多指教~

    python实现文件的备份流程详解

    python实现输入要备份的文件名称:test.txt 12行代码实现文件备份功能 第一步:打开我们的pycharm软件,然后新建一个Python文件 第二步:新建好我们的Python文件后,我们在编辑界面输入以下代码: oldfilename=...

    Python实现备份文件实例

    本文实例讲述了Python实现备份文件的方法,是一个非常实用的技巧。分享给大家供大家参考。具体方法如下: 该实例主要实现读取一个任务文件, 根据指定的任务参数自动备份. 任务文件的格式: (注意,分号后面注释是不...

    python文件备份源码.rar

    python文件备份源码.rar

    python备份文件的脚本

    实际效果:假设给定目录”/media/data/programmer/project/python” ,备份路径”/home/diegoyun/backup/“ , 则会将python目录下的文件按照全路经备份到备份路径下,形如: /home/diegoyun/backup/yyyymmddHHMMSS/...

    python3实现sqlserver数据库和文件异地备份

    Python3写的脚本,windows上应用的,实现服务器上的数据库通过磁盘映射备份到本地其他机器上的共享文件夹中,服务器上指定文件夹下的文件也备份到指定共享文件夹中,并发邮件通知

    基于Python的文件备份功能

    在windows环境下通过Python对重要的文件进行备份,备份的文件将打包为zip格式。由于windows环境下不提供标准的zip命令进行打包,因此要通过GnuWin32安装zip命令,并将C:\Program Files (x86)\GnuWin32\bin添加到系统...

    使用python自动备份文件打包脚本

    使用python语言写的打包备份文件脚本,使用tar命令进行打包。自定义备份目录,和备份源文件目录。

    python定期备份交换机配置文件二

    python定期备份交换机配置文件二

    Python 项目备份文件

    备份文件

    python自动备份mysql数据库,并删除七天前文件

    python自动备份mysql数据库,并删除七天前文件。 省去每天手动备份 删除 空出的时间摸鱼不香吗? 备份时间可自己设置 备份文件夹可自己设置 删除文件时间范围可自己设置

    python Windows 压缩备份文件(支持多文件夹)

    python Windows 压缩备份文件(支持多文件夹)

    python备份文件以及mysql数据库的脚本代码

    /usr/local/python import os import time import string source=[‘/var/www/html/xxx1/’,’/var/www/html/xxx2/’] target_dir=’/backup/’ target=target_dir+time.strftime(‘%Y%m%d’) zip_comm=’zip -r %s ...

    python 简单备份文件脚本v1.0的实例

    下面小编就为大家带来一篇python 简单备份文件脚本v1.0的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望对大家有所帮助

    python备份mysql数据库

    介绍使用python结合mysqldump对mysql数据库进行备份

    用python实现简易文本备份的功能

    用python实现简易文本备份的功能: 主要运用: 1、python的os库 2、文件读写相关操作 """ @author:maoWeiyang @file:yes.py @ide:PyCharm @time:2020/3/1317:57 """ import os import os.path class FileBackup...

    python 华为锐捷交换机备份.zip

    只要是交换机支持ftp都可以用此脚本进行备份,只需要改一下交换机配置文件的名称,不同厂家交换机备份文件名称不一样。同时需要交换机开启ftp

    python交换机自动备份脚本

    py交换机自动备份脚本。支持华为、思科、华三、 Aruba交换机。将设备ip、账号、密码、写入配置文件运行即可。多台设备一键备份。记录日志,自定义备份位置。需要先安装调用的模块,怎么安装自行百度。

Global site tag (gtag.js) - Google Analytics