コード例 #1
0
    def all_backup(self):
        """
         This method at first checks full backup directory, if it is empty takes full backup.
         If it is not empty then checks for full backup time.
         If the recent full backup  is taken 1 day ago, it takes full backup.
         In any other conditions it takes incremental backup.
        """
        # Workaround for circular import dependency error in Python

        # Creating object from CheckEnv class
        check_env_obj = CheckEnv(self.conf, full_dir=self.full_dir, inc_dir=self.inc_dir)

        if check_env_obj.check_all_env():
            if self.recent_full_backup_file() == 0:
                logger.debug("- - - - You have no backups : Taking very first Full Backup! - - - -")

                # Flushing Logs
                if self.mysql_connection_flush_logs():

                    # Taking fullbackup
                    if self.full_backup():
                        # Removing old inc backups
                        self.clean_inc_backup_dir()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(self, 'remote_dir') \
                        and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                return True

            elif self.last_full_backup_date() == 1:
                logger.debug("- - - - Your full backup is timeout : Taking new Full Backup! - - - -")

                # Archiving backups
                if hasattr(self, 'archive_dir'):
                    if (hasattr(self, 'max_archive_duration') and self.max_archive_duration) \
                            or (hasattr(self, 'max_archive_size') and self.max_archive_size):
                        self.clean_old_archives()
                    self.create_backup_archives()
                else:
                    logger.debug("Archiving disabled. Skipping!")

                # Flushing logs
                if self.mysql_connection_flush_logs():

                    # Taking fullbackup
                    if self.full_backup():
                        # Removing full backups
                        self.clean_full_backup_dir()

                        # Removing inc backups
                        self.clean_inc_backup_dir()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(self, 'remote_dir') \
                        and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                return True
            else:

                logger.debug("- - - - You have a full backup that is less than {} seconds old. - - - -".format(
                    self.full_backup_interval))
                logger.debug("- - - - We will take an incremental one based on recent Full Backup - - - -")

                time.sleep(3)

                # Taking incremental backup
                self.inc_backup()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(self, 'remote_dir') \
                        and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                return True
コード例 #2
0
    def all_backup(self):
        """
         This function at first checks full backup directory, if it is empty takes full backup.
         If it is not empty then checks for full backup time.
         If the recent full backup  is taken 1 day ago, it takes full backup.
         In any other conditions it takes incremental backup.
        """
        # Workaround for circular import dependency error in Python

        # Creating object from CheckEnv class
        check_env_obj = CheckEnv(self.conf)

        if check_env_obj.check_all_env():

            if self.recent_full_backup_file() == 0:
                logger.debug(
                    "###############################################################"
                )
                logger.debug(
                    "#You have no backups : Taking very first Full Backup! - - - - #"
                )
                logger.debug(
                    "###############################################################"
                )

                time.sleep(3)

                # Flushing Logs
                if self.mysql_connection_flush_logs():

                    # Taking fullbackup
                    if self.full_backup():
                        # Removing old inc backups
                        self.clean_inc_backup_dir()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(
                        self,
                        'remote_dir') and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                # Exiting after taking full backup
                exit(0)

            elif self.last_full_backup_date() == 1:
                logger.debug(
                    "################################################################"
                )
                logger.debug(
                    "Your full backup is timeout : Taking new Full Backup!- - - - - #"
                )
                logger.debug(
                    "################################################################"
                )

                time.sleep(3)

                # Archiving backups
                if self.archive_dir:
                    if (hasattr(self, 'max_archive_duration')
                            and self.max_archive_duration) or (
                                hasattr(self, 'max_archive_size')
                                and self.max_archive_size):
                        self.clean_old_archives()
                    if not self.create_backup_archives():
                        exit(0)

                # Flushing logs
                if self.mysql_connection_flush_logs():

                    # Taking fullbackup
                    if self.full_backup():
                        # Removing full backups
                        self.clean_full_backup_dir()

                        # Removing inc backups
                        self.clean_inc_backup_dir()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(
                        self,
                        'remote_dir') and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                # Exiting after taking NEW full backup
                exit(0)

            else:
                logger.debug(
                    "################################################################"
                )
                logger.debug(
                    "You have a full backup that is less than %d seconds old. - -#",
                    self.full_backup_interval)
                logger.debug(
                    "We will take an incremental one based on recent Full Backup - -#"
                )
                logger.debug(
                    "################################################################"
                )

                time.sleep(3)

                # Taking incremental backup
                self.inc_backup()

                # Copying backups to remote server
                if hasattr(self, 'remote_conn') and hasattr(
                        self,
                        'remote_dir') and self.remote_conn and self.remote_dir:
                    self.copy_backup_to_remote_host()

                # Exiting after taking Incremental backup
                exit(0)