[root@ubk-ctc-bj-10-254-9-180 ~]# cat AwCheckBackupFile.py 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "月影鹏鹏"
__date__ ="$2018-6-15 10:39:40$"



import time
import datetime
import os, sys

'''获取文件的大小,结果保留两位小数,单位为MB'''
def get_FileSize(filePath):
        filePath = unicode(filePath,'utf8')
        fsize = os.path.getsize(filePath)
        fsize = fsize/float(1024*1024)
        return round(fsize,2)



'''获取文件的创建时间'''
def get_FileCreateTime(filePath):
        #filePath = unicode(filePath,'utf8')
        t = os.path.getctime(filePath)
        return TimeStampToTime(t)



'''备份文件时间匹配'''
def get_BackupFileName(backfiletemp ,TimeDifference):
        backtime = time.time() - int(TimeDifference)
        backfile=time.strftime(backfiletemp ,time.localtime(backtime))
        #print backfile
        return backfile 





def main():
    try:
        BackFile=get_BackupFileName(sys.argv[1],sys.argv[2])
        FileSize=get_FileSize(BackFile)
        print FileSize
    except getopt.error, msg:
        #判断文件出错返回 -1
        FileSize=-1
        print FileSize







if __name__ == "__main__":
    main()
文档更新时间: 2019-06-14 13:38   作者:月影鹏鹏