(self)
Rotate backups by increasing backup directory suffixes. Note that since
        we also have to make room for next backup, we actually have
        keep_backups - 1 backups available after this.

        Unneeded WAL files are not removed here, handled by xpurgewals command instead.
Rotate backups by increasing backup directory suffixes. Note that since
        we also have to make room for next backup, we actually have
        keep_backups - 1 backups available after this.
Rotate backups by increasing backup directory suffixes . Note that since we also have to make room for next backup we actually have keep_backups - 1 backups available after this .
def slave_rotate_backups(self):
        """
        Rotate backups by increasing backup directory suffixes. Note that since
        we also have to make room for next backup, we actually have
        keep_backups - 1 backups available after this.

        Unneeded WAL files are not removed here, handled by xpurgewals command instead.
        """
        self.assert_is_master(False)
        dst_loc = self.cf.getfile("full_backup")
        maxbackups = self.cf.getint("keep_backups", 0)
        archive_command = self.cf.get("archive_command", "")

        backupdirs = self.get_backup_list(dst_loc)
        if not backupdirs or maxbackups < 1:
            self.log.debug("Nothing to rotate")

        # remove expired backups
        while len(backupdirs) >= maxbackups and len(backupdirs) > 0:
            last = backupdirs.pop()

            # if archive_command is set, run it before removing the directory
            # Resume only if archive command succeeds.
            if archive_command:
                cmdline = archive_command.replace("$BACKUPDIR", last)
                self.log.info("Executing archive_command: %s", cmdline)
                rc = self.exec_system(cmdline)
                if rc != 0:
                    self.log.error("Backup archiving returned %d, exiting!", rc)
                    sys.exit(1)

            self.log.info("Removing expired backup directory: %s", last)
            if self.not_really:
                continue
            cmdline = [ "rm", "-r", last ]
            self.exec_cmd(cmdline)

        # bump the suffixes if base directory exists
        if os.path.isdir(dst_loc):
            backupdirs.sort(lambda x,y: self.order_backupdirs(dst_loc, y,x))
            for dir in backupdirs:
                (name, index) = os.path.splitext(dir)
                if not re.match('\.[0-9]+$', index):
                    name = name + index
                    index = 0
                else:
                    index = int(index[1:])+1
                self.log.debug("Rename %s to %s.%s", dir, name, index)
                if self.not_really:
                    continue
                os.rename(dir, "%s.%s" % (name,index))
def slave_rotate_backups ( self ) : self . assert_is_master ( False ) dst_loc = self . cf . getfile ( "full_backup" ) maxbackups = self . cf . getint ( "keep_backups" , 0 ) archive_command = self . cf . get ( "archive_command" , "" ) backupdirs = self . get_backup_list ( dst_loc ) if not backupdirs or maxbackups < 1 : self . log . debug ( "Nothing to rotate" ) # remove expired backups while len ( backupdirs ) >= maxbackups and len ( backupdirs ) > 0 : last = backupdirs . pop ( ) # if archive_command is set, run it before removing the directory # Resume only if archive command succeeds. if archive_command : cmdline = archive_command . replace ( "$BACKUPDIR" , last ) self . log . info ( "Executing archive_command: %s" , cmdline ) rc = self . exec_system ( cmdline ) if rc != 0 : self . log . error ( "Backup archiving returned %d, exiting!" , rc ) sys . exit ( 1 ) self . log . info ( "Removing expired backup directory: %s" , last ) if self . not_really : continue cmdline = [ "rm" , "-r" , last ] self . exec_cmd ( cmdline ) # bump the suffixes if base directory exists if os . path . isdir ( dst_loc ) : backupdirs . sort ( lambda x , y : self . order_backupdirs ( dst_loc , y , x ) ) for dir in backupdirs : ( name , index ) = os . path . splitext ( dir ) if not re . match ( '\.[0-9]+$' , index ) : name = name + index index = 0 else : index = int ( index [ 1 : ] ) + 1 self . log . debug ( "Rename %s to %s.%s" , dir , name , index ) if self . not_really : continue os . rename ( dir , "%s.%s" % ( name , index ) )