org.zeroturnaround.zip.ZipException: Given file '/root/DB_Backup/sql' doesn't exist

Viewed 9

I am using mysql-backup4j in my Spring Boot application reference https://github.com/SeunMatt/mysql-backup4j. I have made a cron job that will trigger this backup creation every day on a specific time. Following is my code:

@Scheduled(cron = "0 18 17 * * ?")
    public void dbBackup() {
        Date date = new Date();
        String currentDateAndTime = CommonUtils.dateToString(date, Constants.DATE_TIME_FORMAT_FRONTEND);
        try {
            // Required properties for exporting of DB
            Properties properties = new Properties();
            properties.setProperty(MysqlExportService.DB_NAME, databaseName);
            properties.setProperty(MysqlExportService.DB_USERNAME, databaseUserName);
            properties.setProperty(MysqlExportService.DB_PASSWORD, databasePassword);
            // Generated ZIP file must be preserved otherwise, it will be deleted automatically.
            properties.setProperty(MysqlExportService.PRESERVE_GENERATED_ZIP, "false");
            properties.setProperty(MysqlExportService.JDBC_DRIVER_NAME, databaseDriverName);
            // set the output directory
            properties.setProperty(MysqlExportService.TEMP_DIR, new File(Constants.DB_BACKUP_BASE_DIRECTORY).getPath());
            MysqlExportService mysqlExportService = new MysqlExportService(properties);
            mysqlExportService.export();
            mysqlExportService.clearTempFiles();

            LOGGER.info("Database backup generated for Date:  " + currentDateAndTime);
        } catch (Exception ex) {
            LOGGER.error("Exception occured while creating the database backup and error is: " + ex);
        }
    }

The thing is, the code is working fine on my local machine but it is causing org.zeroturnaround.zip.ZipException: Given file '/root/DB_Backup/sql' doesn't exist! error on the production. The backup is being stored at this DB_backup folder and this folder is automatically generated by mysql-backup4j. There is no folder named sql after DB_backup folder that is why, I am not sure why is it trying to open this when I have not defined it anywhere.

0 Answers
Related