-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to upload on any cloud? #8
Comments
Hello @ypkkhatri Here's an example snippet from one of my projects. public boolean backup() {
Properties properties = new Properties();
properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, dataSourceProperties.getUrl());
properties.setProperty(MysqlExportService.DB_USERNAME, dataSourceProperties.getUsername());
properties.setProperty(MysqlExportService.DB_PASSWORD, dataSourceProperties.getPassword());
properties.setProperty(MysqlExportService.PRESERVE_GENERATED_ZIP, "true");
properties.setProperty(MysqlExportService.ADD_IF_NOT_EXISTS, "true");
String basePath = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
File tempFile = new File(basePath, "/backup");
properties.setProperty(MysqlExportService.TEMP_DIR, tempFile.getPath());
MysqlExportService mySqlExportService = new MysqlExportService(properties);
try {
mySqlExportService.export();
storageService.storeBackupFile(mySqlExportService.getGeneratedZipFile());
return true;
} catch (Exception e) {
logger.error("Error Occurred in DatabaseBackupService: " + e.getLocalizedMessage());
e.printStackTrace();
return false;
} finally {
mySqlExportService.clearTempFiles(false);
}
} I configured the properties Which is exactly what I did here In my case, the Here is the implementation of that public void storeBackupFile(File file) {
if(!Objects.isNull(file)) {
String newFileName = RandomStringUtils.randomAlphanumeric(5) + "_" + file.getName();
AmazonS3 s3 = s3Factory();
String bucketName = storageProperties.getAwsS3BucketName() + "/backup";
Try.of(() -> s3.putObject(
new PutObjectRequest(bucketName, newFileName, new FileInputStream(file), null)
.withCannedAcl(CannedAccessControlList.PublicRead)))
.onFailure(e -> logger.error("Error Storing Object to S3: " + e.getLocalizedMessage())).get();
}
} I hope this helps you. Cheers |
@SeunMatt Thanks, for example,. |
Can you please show the information or code to upload on any cloud? Because in your code its not mentioned.
The text was updated successfully, but these errors were encountered: