backups.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:smartbackup 作者: baszoetekouw 项目源码 文件源码
def watch_backups(machines):
    # set nice and ionice for current process
    os.setpriority(os.PRIO_PROCESS, 0, 10)
    p = psutil.Process(os.getpid())
    p.ionice(psutil.IOPRIO_CLASS_IDLE)

    i = inotify.adapters.Inotify()

    # TODO watch all paths
    for name in machines:
        d = os.path.join(BU_SYNC_DIR,name)
        i.add_watch( d.encode('utf-8') )
        print( "Start watching {}".format(d) )

    # wait for an inotify event
    for event in i.event_gen():
        if event is None: 
            continue

        # decode event info
        (header, type_names, watch_path, filename) = event
        watch_path = watch_path.decode('utf-8')
        filename   = filename.decode('utf-8')

        # only take action of the stamp file was updated
        if filename != 'stamp': 
            continue

        if header.mask & (inotify.constants.IN_MOVED_TO|inotify.constants.IN_CLOSE_WRITE):
            # only got here if a backup just finished
            _LOGGER.info("WD=(%d) MASK=(%d) COOKIE=(%d) LEN=(%d) MASK->NAMES=%s "
                "WATCH-PATH=[%s] FILENAME=[%s]",
                header.wd, header.mask, header.cookie, header.len, type_names,
                watch_path, filename)
            try:
                # handle the new backup
                new_backup(watch_path)
            except BackupError as e:
                _LOGGER.error(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号