您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)Python中怎么實(shí)現(xiàn)增量備份,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
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): #如果在備份目錄中文件夾不存在則創(chuàng)建 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: #如果文件已經(jīng)存在,則比較文件修改時(shí)間 if os.path.isfile(file_path_bak): stat_bak = os.stat(file_path_bak) stat_source = os.stat(file_path) #判斷文件修改時(shí)間 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中怎么實(shí)現(xiàn)增量備份了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。