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)
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)
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)