温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python中怎么实现增量备份

发布时间:2021-07-05 16:39:31 来源:亿速云 阅读:227 作者:Leah 栏目:编程语言

这期内容当中小编将会给大家带来有关Python中怎么实现增量备份,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

Python增量备份代码示例:

#!/usr/bin/python  #-*-coding:utf-8-*-  #Filename: auto_bak.py  #Author: zz  import os  import sys  def get_dir(path):  print path, '\n'  return os.listdir(path)  def bak_file(path,path_bak):  list = os.listdir(path)  for l in list:  file_path = os.path.join(path, l)  file_path_bak = os.path.join(path_bak, l)  print file_path  #如果文件路径为目录  if os.path.isdir(file_path):  #如果在备份目录中文件夹不存在则创建  if not os.path.isdir(file_path_bak):  create_com = '''mkdir -p '%s' ''' \  % (file_path_bak)  if os.system(create_com) == 0:  print create_com   else:  print 'create folder failure!'  os._exit(0)   bak_file(file_path, file_path_bak)  else:  #如果文件已经存在,则比较文件修改时间  if os.path.isfile(file_path_bak):  stat_bak = os.stat(file_path_bak)  stat_source = os.stat(file_path)  #判断文件修改时间  if stat_source.st_mtime <= stat_bak.st_mtime:  continue  cp_com = '''cp '%s' '%s' ''' \  % (file_path, file_path_bak)  if os.system(cp_com) == 0:   print cp_com  else:   print 'create folder failure!'  os._exit(0)   #要备份的文件目录  path = '/home/zyf/appspot/auto_bak/a' #备份文件目录  path_bak = '/home/zyf/appspot/auto_bak/bak' #开始备份  bak_file(path, path_bak)

上述就是小编为大家分享的Python中怎么实现增量备份了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI