# Path: mongodb_consistent_backup/Errors.py
# class OperationError(Error):
#     """Raised when an operation failed in an expected but unrecoverable way"""
#     pass


import logging
import os
from math import ceil
from shutil import rmtree
from time import time
from mongodb_consistent_backup.Errors import OperationError
        for ts in sorted(self.backups.iterkeys(), reverse=True):
            backup = self.backups[ts]
            name   = backup["name"].encode("ascii", "ignore")
            if self.max_backups == 0 or kept_backups < self.max_backups:
                if self.max_secs > 0 and (now - ts) > self.max_secs:
                    remove_backups[name] = ts
                    continue
                logging.debug("Keeping previous backup %s" % name)
                kept_backups += 1
            else:
                remove_backups[name] = ts
        if len(remove_backups) > 0:
            logging.info("Backup(s) exceeds max backup count or age, removing: %s" % sorted(remove_backups.keys()))
            for name in remove_backups:
                self.remove(remove_backups[name])

    def symlink(self):
        try:
            if os.path.islink(self.latest_symlink):
                os.remove(self.latest_symlink)
            logging.info("Updating %s latest symlink to current backup path: %s" % (self.backup_name, self.latest["path"]))
            os.symlink(self.latest["path"], self.latest_symlink)

            if os.path.islink(self.previous_symlink):
                os.remove(self.previous_symlink)
            if self.previous:
                logging.info("Updating %s previous symlink to: %s" % (self.backup_name, self.previous["path"]))
                os.symlink(self.previous["path"], self.previous_symlink)
        except Exception, e:
            logging.error("Error creating backup symlinks: %s" % e)

# Path: mongodb_consistent_backup/Errors.py
# class OperationError(Error):
#     """Raised when an operation failed in an expected but unrecoverable way"""
#     pass


# Path: mongodb_consistent_backup/Rotate.py
import logging
import os
from math import ceil
from shutil import rmtree
from time import time
from mongodb_consistent_backup.Errors import OperationError

        for ts in sorted(self.backups.iterkeys(), reverse=True):
            backup = self.backups[ts]
            name   = backup["name"].encode("ascii", "ignore")
            if self.max_backups == 0 or kept_backups < self.max_backups:
                if self.max_secs > 0 and (now - ts) > self.max_secs:
                    remove_backups[name] = ts
                    continue
                logging.debug("Keeping previous backup %s" % name)
                kept_backups += 1
            else:
                remove_backups[name] = ts
        if len(remove_backups) > 0:
            logging.info("Backup(s) exceeds max backup count or age, removing: %s" % sorted(remove_backups.keys()))
            for name in remove_backups:
                self.remove(remove_backups[name])

    def symlink(self):
        try:
            if os.path.islink(self.latest_symlink):
                os.remove(self.latest_symlink)
            logging.info("Updating %s latest symlink to current backup path: %s" % (self.backup_name, self.latest["path"]))
            os.symlink(self.latest["path"], self.latest_symlink)

            if os.path.islink(self.previous_symlink):
                os.remove(self.previous_symlink)
            if self.previous:
                logging.info("Updating %s previous symlink to: %s" % (self.backup_name, self.previous["path"]))
                os.symlink(self.previous["path"], self.previous_symlink)
        except Exception, e:
            logging.error("Error creating backup symlinks: %s" % e)

            raise OperationError(e)