예제 #1
0
    def default(self, path=b"", date="", failures=""):
        validate_isinstance(date, str)

        # Validate date
        startTime = librdiff.RdiffTime() - timedelta(days=5)
        endTime = None
        if date:
            try:
                date = int(date)
            except:
                logger.exception("invalid date")
                raise cherrypy.HTTPError(400, _("Invalid date."))
            # Set the start and end time to be the start and end of the day,
            # respectively, to get all entries for that day
            startTime = librdiff.RdiffTime(date)
            startTime.set_time(0, 0, 0)
            endTime = librdiff.RdiffTime(date)
            endTime.set_time(23, 59, 59)

        # Limit the scope to the given path.
        if path:
            user_repos = [self.app.store.get_repo(path)]
        else:
            user_repos = self.app.currentuser.repo_objs

        failuresOnly = failures != ""
        messages = self._getUserMessages(user_repos, not failuresOnly, True,
                                         startTime, endTime)

        return self._compile_template("status.html",
                                      messages=messages,
                                      failuresOnly=failuresOnly)
예제 #2
0
    def send_notifications(self):
        """
        Loop trough all the user repository and send notifications.
        """

        now = librdiff.RdiffTime()

        def _user_repos():
            """Return a generator trought user repos to be notified."""
            for user in self.app.store.users():
                # Check if user has email.
                if not user.email:
                    continue
                # Identify old repo for current user.
                old_repos = []
                for repo in user.repo_objs:
                    # Check if repo has age configured (in days)
                    maxage = repo.maxage
                    if not maxage or maxage <= 0:
                        continue
                    # Check repo age.
                    if repo.last_backup_date < (
                            now - datetime.timedelta(days=maxage)):
                        old_repos.append(repo)
                # Return an item only if user had old repo
                if old_repos:
                    yield user, old_repos

        # For each candidate, send mail.
        for user, repos in _user_repos():
            parms = {'user': user, 'repos': repos}
            self.send_mail(user, _('Notification'), 'email_notification.html',
                           **parms)
예제 #3
0
    def _remove_older(self, repo):
        """
        Take action to remove older.
        """
        assert repo
        if repo.keepdays <= 0:
            return
        # Check history date.
        if not repo.last_backup_date:
            _logger.info("no backup dates for [%r]", repo.full_path)
            return
        d = librdiff.RdiffTime() - repo.last_backup_date
        d = d.days + repo.keepdays

        repo.remove_older(d)
예제 #4
0
    def _remove_older(self, user, repo, keepdays):
        """
        Take action to remove older.
        """
        assert isinstance(keepdays, int)
        assert keepdays > 0
        # Get instance of the repo.
        r = librdiff.RdiffRepo(user.user_root, repo.name)
        # Check history date.
        if not r.last_backup_date:
            _logger.info("no backup dates for [%r]", r.full_path)
            return
        d = librdiff.RdiffTime() - r.last_backup_date
        d = d.days + keepdays

        r.remove_older(d)
예제 #5
0
    def _remove_older(self, user, repo, keepdays):
        """
        Take action to remove older.
        """
        assert isinstance(keepdays, int)
        assert keepdays > 0
        # Get instance of the repo.
        r = librdiff.RdiffRepo(user.user_root, repo.name)
        # Check history date.
        if not r.last_backup_date:
            _logger.info("no backup dates for [%r]", r.full_path)
            return
        d = librdiff.RdiffTime() - r.last_backup_date
        d = d.days + keepdays

        _logger.info("execute rdiff-backup --force --remove-older-than=%sD %r",
                     d, r.full_path)
        r.execute(
            b'--force',
            b'--remove-older-than=' + str(d).encode(encoding='latin1') + b'D',
            r.full_path)