检查备份情况的脚本

#-*-coding:gbk-*- #gbk可以识别windows文件里面的中文
import os
import sys
def check_backup_info(path):
    print('\n')
    filelist = os.popen('dir /O-D %s > c:/temp.txt' % path).read() #popen可以执行本地命令
    with open('c:/temp.txt') as f:
        print("*************最近备份的文件如下:****************")
        for index,line in  enumerate(f,1):
            if "的卷没有标签" in line:
                pass
            elif "卷的序列号是" in line:
                pass
            elif "字节" in line:
                pass
            
            elif line.split(): #删除空行
                print line
            
            if  index == 12:
                break
    os.remove('c:/temp.txt')
                
#主程序  
if __name__ == '__main__':
        check_backup_info('D:\\数据备份\\BMS3')
        check_backup_info('D:\\数据备份\\IWSDB1040')
        check_backup_info('D:\\数据备份\\U8账套\\001-031')
        check_backup_info('D:\\数据备份\\U8账套\\100-153')
        check_backup_info('D:\\数据备份\\U8账套\\191-195')
        check_backup_info('D:\\数据备份\\U8账套\\545-561')
        check_backup_info('D:\\数据备份\\U8账套\\642-810')
        check_backup_info('D:\\数据备份\\U8账套\\901-960')
        check_backup_info('D:\\数据备份\\客服共享0122')
        check_backup_info('D:\\backup\\LocalUser\\ora12')
        check_backup_info('D:\\backup\\LocalUser\\wyerp')

运行后:

***********最近备份的文件如下:****************

 D:\数据备份\BMS3 的目录

2018-07-14  10:01    <DIR>          ..

2018-07-14  10:01    <DIR>          .

2018-07-14  00:10     2,895,775,744 BMS3_20180714.dmp

2018-07-14  00:10            26,027 BMS3_20180714.log

2018-07-06  09:21                 0 2222222222222222222222222222222.txt

*************最近备份的文件如下:****************

 D:\数据备份\IWSDB1040 的目录

2018-07-14  14:17    <DIR>          ..

2018-07-14  14:17    <DIR>          .

2018-07-13  23:30               207 delete_1040_backup.log

2018-07-13  11:06             6,134 backup.log

2018-07-13  11:06            11,441 IWS_back_20180713.log

2018-07-13  11:06     3,210,194,944 IWS_back_20180713.dmp

2018-07-13  10:59            22,619 TMS_back_20180713.log

    原文作者:czxin788
    原文地址: http://blog.itpub.net/28916011/viewspace-2157864/
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞