예제 #1
0
 def do_backup(self):
     self.backup_file_name = "{}.{}".format(self.file_name,
                                            get_date_with_file_format())
     with open(self.get_backup_file_path(), "wb+") as file:
         popen = BackupJob.popen(self.mysql_client.get_backup_bash_cmd(
             self.mysql_backup),
                                 stdout=file,
                                 stderr=PIPE)
         file.seek(0)
         stderr_txt = popen.stderr.read().decode()
         self.get_info().add(stderr_txt)
         BackupJob.exception_by_return_code(popen, [0], stderr=stderr_txt)
    def do_backup(self):
        self.backup_file_name = "{}.{}".format(self.from_file_name,
                                               get_date_with_file_format())

        popen = BackupJob.popen(self.ssh_client.rsync_from_remote_to_local(
            self.filesystem_backup.get_from_path(),
            self.get_backup_file_path()),
                                stdout=PIPE,
                                stderr=PIPE)
        stdout_txt = popen.stdout.read().decode()
        stderr_txt = popen.stderr.read().decode()
        self.get_info().add(stdout_txt)
        self.get_info().add(stderr_txt)
        BackupJob.exception_by_return_code(popen, [0], stdout_txt, stderr_txt)
예제 #3
0
 def __init__(self, mysql_backup_check: MySQLBackupCheck):
     self.mysql_backup_check = mysql_backup_check
     self.mysql_client_main = MySQLClient(
         self.mysql_backup_check.get_mysql_backup().get_mysql_creds())
     self.backups_wildcard = "{}/{}/mysql/{}/*".format(
         BackupJob.get_backups_dir(),
         self.mysql_backup_check.get_mysql_backup().get_mysql_db(
         ).get_mysql().get_machine().get_address(),
         self.mysql_backup_check.get_mysql_backup().get_mysql_db().
         get_db_name())
     self.info = ListInfo()
 def __init__(self, filesystem_backup: FilesystemBackup):
     super().__init__()
     self.filesystem_backup = filesystem_backup
     self.ssh_client = SSHClient(self.filesystem_backup.get_ssh_creds())
     self.backup_file_name = None
     self.backup_dir_path = "{}/{}/files/{}".format(
         BackupJob.get_backups_dir(),
         self.filesystem_backup.get_ssh_creds().get_ssh().get_machine().
         get_address(), self.filesystem_backup.get_to_dir())
     self.from_file_name = get_unix_basename(
         self.filesystem_backup.get_from_path())
예제 #5
0
 def __init__(self, mysql_backup: MySQLBackup):
     super().__init__()
     self.mysql_backup = mysql_backup
     self.mysql_client = MySQLClient(self.mysql_backup.get_mysql_creds())
     self.backup_file_name = None
     self.backup_dir_path = "{}/{}/mysql/{}".format(
         BackupJob.get_backups_dir(),
         self.mysql_backup.get_mysql_db().get_mysql().get_machine().
         get_address(),
         self.mysql_backup.get_mysql_db().get_db_name())
     self.file_name = self.mysql_backup.get_mysql_db().get_db_name(
     ) + ".sql"
예제 #6
0
    def do_backup(self):
        self.backup_file_name = "{}.{}".format(self.backup_name,
                                               get_date_with_file_format())
        log_file_name = "{}.{}".format(self.log_name,
                                       get_date_with_file_format())
        remote_directory_path = self.oracle_client.get_directory_path(
            self.oracle_backup.get_oracle_dir_name())
        remote_backup_path = "{}/{}".format(remote_directory_path,
                                            self.backup_file_name)

        # Create backup
        popen = BackupJob.popen(self.ssh_client.popen_cmd(
            self.oracle_client.get_backup_bash_cmd(self.oracle_backup,
                                                   self.backup_file_name,
                                                   log_file_name)),
                                stdout=PIPE,
                                stderr=PIPE)
        stdout_txt = popen.stdout.read().decode()
        stderr_txt = popen.stderr.read().decode()
        self.get_info().add(stdout_txt)
        self.get_info().add(stderr_txt)
        BackupJob.exception_by_return_code(popen, [0], stdout_txt, stderr_txt)

        # Move backup to local repository
        popen = BackupJob.popen(self.ssh_client.rsync_from_remote_to_local(
            remote_backup_path, self.get_backup_file_path()),
                                stdout=PIPE,
                                stderr=PIPE)
        stdout_txt = popen.stdout.read().decode()
        stderr_txt = popen.stderr.read().decode()
        self.get_info().add(stdout_txt)
        self.get_info().add(stderr_txt)
        BackupJob.exception_by_return_code(popen, [0], stdout_txt, stderr_txt)

        # Delete backup from remote machine
        popen = BackupJob.popen(self.ssh_client.popen_cmd(
            ["rm", "-f", remote_backup_path]),
                                stdout=PIPE,
                                stderr=PIPE)
        stdout_txt = popen.stdout.read().decode()
        stderr_txt = popen.stderr.read().decode()
        self.get_info().add(stdout_txt)
        self.get_info().add(stderr_txt)
        BackupJob.exception_by_return_code(popen, [0], stdout_txt, stderr_txt)
예제 #7
0
 def do(self):
     latest_backup = get_last_modified_file_from_wildcard(
         self.backups_wildcard)
     self.mysql_client_test.drop_db(self.mysql_db_test)
     self.mysql_client_test.create_db(self.mysql_db_test)
     with gzip_open(latest_backup) as backup:
         BackupJob.popen(self.mysql_client_test.get_mysql_db_cmd(
             self.mysql_db_test),
                         stdin=backup)
     mysql_backup_cmd = \
         MySQLClient.get_mysqldbcompare_cmd(
             self.mysql_creds_test, self.mysql_db_test,
             self.mysql_backup_check.get_mysql_backup().get_mysql_creds(),
             self.mysql_backup_check.get_mysql_backup().get_mysql_db().get_db_name()
         )
     with TemporaryFile() as file:
         popen = BackupJob.popen(mysql_backup_cmd, stdout=file, stderr=PIPE)
         file.seek(0)
         stdout_txt = file.read().decode()
         stderr_txt = popen.stderr.read().decode()
         self.get_info().add(stdout_txt)
         self.get_info().add(stderr_txt)
         BackupJob.exception_by_return_code(popen, [0], stdout_txt,
                                            stderr_txt)
예제 #8
0
 def __init__(self, oracle_backup: OracleBackup):
     super().__init__()
     self.oracle_backup = oracle_backup
     self.oracle_client = OracleClient(
         self.oracle_backup.get_oracle_creds())
     self.ssh_client = SSHClient(self.oracle_backup.get_ssh_creds())
     self.backup_file_name = None
     self.backup_dir_path = "{}/{}/oracle/{}".format(
         BackupJob.get_backups_dir(),
         self.oracle_backup.get_oracle_schema().get_oracle_sid().get_oracle(
         ).get_machine().get_address(),
         self.oracle_backup.get_oracle_schema().get_schema_name())
     self.backup_name = self.oracle_backup.get_oracle_schema(
     ).get_schema_name() + ".dmp"
     self.log_name = self.oracle_backup.get_oracle_schema().get_schema_name(
     ) + ".log"
예제 #9
0
# CLI logs
task_manager.logs.add_log(CLILog())
task_manager.error_logs.add_log(CLILog())
CLI.logs.add_log(CLILog())

# Email Alerts
#task_manager.alerts.add_alert(EmailAlert("Backups", "*****@*****.**"))
task_manager.alerts.add_alert(EmailAlert("Backups", "[email protected],[email protected]"))


mysql_backups = load_mysql_backups()
mysql_backup_checks = load_mysql_backup_checks()
oracle_backups = load_oracle_backups()
filesystem_backups = load_filesystem_backups()

for backup in mysql_backups:
    task_manager.add_scheduled_task(ScheduledTask(BackupJob(MySQLBackupSubJob(backup)), backup))

for backup in oracle_backups:
    task_manager.add_scheduled_task(ScheduledTask(BackupJob(OracleBackupSubJob(backup)), backup))

for backup in filesystem_backups:
    task_manager.add_scheduled_task(ScheduledTask(BackupJob(FilesystemBackupSubJob(backup)), backup))

for backup_check in mysql_backup_checks:
    task_manager.add_scheduled_task(ScheduledTask(MySQLBackupCheckJob(backup_check), backup_check))

while True:
    task_manager.run_next_task()