Database backup is a java system for generate PostgreSQL and Mysql backups. This is a linux documentation to install, schedulle and run the jar file for generate your backups.
Technologies
- Java
- PostgreSQL
- Mysql
- Cron
With eclipse
- Clone the project
- Eclipse: File -> Import -> Maven -> Existing Maven Projects
- Select the project folder
- Run the class Bootstrap.java
Use the fatjar plugin to pack the jar file, adding all libs just one jar. See the link below to know more about fat jar
Create the folders
$ mkdir /etc/database_backup
$ mkdir /opt/backups
Move the generated file database_backup.jar to folder /etc/database_backup
$ mv {your compiled jar} /etc/database_backup
Example:
$ mv /opt/database_backup.jar /etc/database_backup
If you wish, download the compiled jar file: database_backup-1.7.jar
$ wget https://github.com/fabriciojf/postgresql-backup/releases/download/1.7/database_backup-1.7.jar
Execute the jar file to create a initial configuration at /etc/database_backup folder
$ java -jar /etc/database_backup/database_backup.jar
See the file models
- register - use this file to register your databases to backup.
- settings - use this file to register a folder to alocate your backups.
Edit the file /etc/database_backup/register adding the database configurations following the role:
host database user pass label type[postgre ou mysql]
Example:
127.0.0.1 dbuser postgres XXXX== userdatabase postgre
127.0.0.1 cms root XXXX== cmsdatabase mysql
- In the above example, first line is generating a PostgreSQL backup and below a Mysql Backup.
- XXXX== is the encrypted password
To register a new backup in the register file is necessary to encrypt the password before. For this, follow the tip below.
Run the jar file passing the password, generating a new encrypted string.
$ java -jar /etc/database_backup/database_backup.jar PASSWORD
Change the register file introducing the encrypted password in the corresponding line.
If you wish, clean the terminal history with the command below.
$ history -c
Type crontab -e in the linux terminal.
$ crontab -e
Insert a call to database_backup.jar at the end of the file cron. In the case below, the backup will be generated all days at 23:00 o'clock.
0 23 * * * java -jar /etc/database_backup/database_backup.jar
Fabricio S Costa - [email protected]