Skip to content

A helper library to backup database dump to various destinations.

Notifications You must be signed in to change notification settings

jdbbackup/jdbbackup-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central License Quality Gate Status javadoc

JDbBackup-core

A helper library to backup data to various destinations.

The JDbBackup class uses a SourceManager to save data to a temporary file. Then it delegates to a DestinationManager the task to save this temporary file to its final destination.

Source and destinations are defined by strings that may start with respectively the SourceManager or the DestinationManager identifier. For instance, sftp:// identifies the DestinationManager able to send a file through the sftp protocol.
The rest of the source and destination addresses depends on the SourceManager/DestinationManager.
Have a look to their javadoc to have more details.

That said, unless otherwise specified, all managers support the use of the following patterns in addresses (except in the SourceManager/DestinationManager identifier):

  • {d=dateFormat}: dateFormat must be a valid date time pattern as described in SimpleDateFormat documentation.
    For example, the pattern {d=yyyy} will be replaced by the year on 4 characters at runtime.
  • {e=envVar}: envVar must be an existing environment variable whose value will replace the pattern.
  • {p=property}: property must be an existing java System property whose value will replace the pattern.
  • {f=filePath}: filePath must be an existing file whose value will replace the pattern.

SourceManager and DestinationManagers implementations

This library contains the following implementation of SourceManager:

  • mysql. Please note it uses the mysqldump command which must be installed on the machine running this library.

This library contains the following implementation of DestinationManager:

Additionally, here are the officially supported extra plugins:

Type id maven artifact comment
src fake com.fathzer::jdbbackup-fakesource A fake source to help implement destination manager's tests
dest sftp com.fathzer::jdbbackup-sftp Sends backup to a remote server through sftp
dest dropbox com.fathzer::jdbbackup-dropbox Sends backup to a dropbox account
dest s3 com.fathzer::jdbbackup-s3 Sends backup to an Amazon S3 bucket
dest gcs com.fathzer::jdbbackup-gcs Sends backup to a Google Cloud Storage bucket

SourceManagers and DestinationManagers are loaded through the Java service loader standard mechanism. So, it's quite easy to implement your own and use it with this library (Official managers can be used as example).

A class that can be used as command line programs is also available at https://github.com/jdbbackup/jdbbackup-cli.
A class that schedules backups is available at https://github.com/jdbbackup/jdbbackup-cli. This project also contains a ready to work Docker image able to schedule backups.

How to use it

This library requires java 11+.

Here is a usage example:

final JDbBackup bckp = new JDbBackup();
bckp.backup("mysql://{f=dblogin.txt}@db.mycompany.com:3306/mydb", "file://{e=HOME}/backup/db-{d=yyyy}")

This example will backup the db database of db.mycompany.com mysql server in a file contained in the backup folder of user's home directory. The name of the file will ends with the current year. The login used to connect to the database is stored in the dblogin.txt file.

Security notice

The data backed up by JDBBackup passes through a temporary file. This allows the same data source to be saved to multiple destinations without having to extract it again.
The counterpart of this architecture is that it may be necessary, depending on the level of confidentiality of the saved data, to secure access to this file.

This temporary file is created in the JDBBackup.createTempFile() method. It creates the file in the default temporary directory and attempts to ensure that it is readable only by the owner of the account running the program.
If you think the implementation is not safe enough, you can override this method.
You may also encrypt the backup by using your own Source manager that encrypts content on the fly.

TODO

  • In a future release implement tmp file as a Path and not a File in order to allow tmp file as a memory file, for instance.

About

A helper library to backup database dump to various destinations.

Resources

Stars

Watchers

Forks

Packages

No packages published