Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

About the Feature

Note

This feature has been introduced in V0.88 of Bahmni. Please look at Known Issues with DB Backup and Restore incase there is an issue.

Bahmni has different artifacts in the system like patient documents, patient images, DB data etc. There is a possibility that unwanted events may happen such as hard drive failure or data loss due to some wrong SQL (eg: delete sql) mistakenly run by an user. Bahmni as a product should provide mechanism to backup all the artifacts so that if any unwanted event happen then we should be able to recover from the backup so that business continue as usual at the earliest.

Info
titleWhere to store / keep backup files

It is highly recommended that you keep the backup files in a separate external disk and away from the hospital location if possible – to avoid loss of all data in case of a Natural disaster like floods or earthquakes. You can provide the destination path for an external disk as long as you mount it successfully. It is also highly recommended to encrypt the external disk. Please refer Performing a Backup of Bahmni Data on USB or External Drive.

Right now Bahmni backup mechanism supports two categories name file backup and database backup.  Below is the list of supported items

  1. Patient images

  2. Document images

  3. Uploaded files

  4. Uploaded lab results

  5. PACS images

  6. Report module generated files by Queue feature

  7. MySQL databases

  8. Postgres databases


Old Way of Backup and Restore

Old Way Backup

Note

This will perform ONLY the DB backup and NOT of the other files (artifacts).

When the backup tools for MySQL and Postgres are not installed then the backup will fall back to old way of DB backups by using following commands. The following commands will achieve same as mentioned in old way of DB backups.

Please replace the inventory_file_name with appropriate file name. For example, in the below examples local is the inventory file name.

Code Block
languagebash
themeConfluence
titleFull Openelis/clinlims DB Backup (Old way)
bahmni -i local backup --backup_type=db  --options=clinlims


Code Block
titleFull Openerp DB Backupup (Old way)
bahmni -i local backup --backup_type=db  --options=openerp


Code Block
titleFull Openmrs DB Backup (Old Way)
bahmni -i local backup --backup_type=db  --options=openmrs


Code Block
titleUninstall Backup Tools
If backrest tools are already installed, then uninstall them to perform oldway backup.
To uninstall pgsql backup tool, execute the following commands

sudo rm -f /usr/bin/pgbackrest
sudo rm -f /usr/bin/pg_backrest
sudo rm -rf /usr/lib/perl5/BackRest
sudo rm -rf /usr/share/perl5/BackRest
sudo rm -rf /usr/lib/perl5/pgBackRest
sudo rm -rf /usr/share/perl5/pgBackRest

To uninstall mysql backup tool, execute the following command
yum list installed | grep xtrabackup|xargs yum remove -y


Old Way Restore

Please replace the inventory_file_name with appropriate file name. For example, in the below examples local is the inventory file name.

Code Block
languagebash
themeConfluence
titleRestore clinlims/openelis database
 bahmni -i local restore --restore_type=db --options=clinlims  --strategy=dump --restore_point=clinlims_dump_20170215-150418.sql.gz


Code Block
languagebash
themeConfluence
titleRestore openerp database
 bahmni -i local restore --restore_type=db --options=openerp  --strategy=dump --restore_point=openerp_dump_20170215-150418.sql.gz


Code Block
languagebash
titleRestore openmrs db (old way)
bahmni -i local restore --restore_type=db --options=openmrs --strategy=dump   --restore_point=openmrs_dump_20170221084218.sql.gz

Complete / Full Backup

Info

The backup tools for MySQL, Postgres and Artifacts have to be installed for the following commands. The Bahmni installation will take care of installing these tools based on provided configuration. Please refer Configure backup.

In order to backup all the possible files and databases, please use the below mentioned command. 

Code Block
bahmni -i <inventory_file_name> backup --backup_type=all --options=all 

Please replace the inventory_file_name with appropriate file name. For Example, in the below example local is the inventory file name.

Code Block
languagebash
themeConfluence
titleCommand to backup everything (databases, files)
  bahmni -i local backup --backup_type=all --options=all

Schedule Backup:

In order to schedule a backup one can use --schedule option available in command line which adds cron entry for the user to run the command as per schedule.

Tip
titleExample Scenario

--schedule "30 2 * * 0" is an example schedule option that can be added to any of the backup commands. The backup in this case is scheduled for every Sunday 2.30 am


Code Block
titleSample command
 bahmni -i <inventory_file_name> backup --backup_type=<file/db> --options=<options_possible> --strategy=<strategy> --schedule "* * * * *"


Code Block
titleExample Scheduling Full Backup command for Openmrs Database
  bahmni -i local backup --backup_type=db --options=openmrs --strategy=full --schedule "30 2 * * 0"


    # Use the hash sign to prefix a comment
    # +---------------- minute (0 - 59)
    # |  +------------- hour (0 - 23)
    # |  |  +---------- day of month (1 - 31)
    # |  |  |  +------- month (1 - 12)
    # |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
    # |  |  |  |  |
    # *  *  *  *  *  command to be executed


Mysql Backup: 

Warning

Taking Backup of all the Mysql Databases with single command is not supported yet.

There are different configurations for mysql database backup command as mentioned below

KeyDefault valueAvailable optionsMandatory
backup_typeallThis value should be db for database backupNo
optionsallThis Value can be either openmrs or bahmni-reports while taking mysql database backup.No
strategyfull

Possible values are full, incr.

No

Mysql Full Backup

One can take full backup of particular mysql database by mentioning the database name.

Tip

For example, in the below sample command DBName should be replaced with the actual database name. Possible values supported right now are "openmrs" or "bahmni-reports".


Code Block
languagebash
themeConfluence
titleSample command for Full backup of MySQL database
  bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName>

Please replace the inventory_file_name with appropriate file name and DBName with the database name. For example, in the below examples local is the inventory file name.

Code Block
languagebash
titleOpenmrs Database Full Backup
bahmni -i local backup --backup_type=db --options=openmrs 


Code Block
languagebash
titleBahmni Reports Database Full Backup
bahmni -i local backup --backup_type=db --options=bahmni_reports 

Mysql Incremental Backup:

Apart from the full backup, there is an option to take incremental backup. In case of incremental backup, strategy should be "incr"

Code Block
titleSample Command for Incremental Backup
bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName>  --strategy=incr

Please replace the inventory_file_name with appropriate file name and DBName with the database name. For example, in the below examples local is the inventory file name.

Code Block
languagebash
themeConfluence
titleOpenmrs Database Incremental Backup
  bahmni -i local backup --backup_type=db --options=openmrs  --strategy=incr


Code Block
languagebash
themeConfluence
titleBahmni Reports Database Incremental Backup
  bahmni -i local backup --backup_type=db --options=bahmni_reports  --strategy=incr


Mysql Database Restore:

Warning

Restoring all the mysql databases with single command is not supported yet.

One can restore to any point (either full or incremental) in database given that the chosen restore points/files are available in configured restore path.

Note
titleHow to find restore path ?

Restore Path is configured in /etc/bahmni-backrest.conf file. More about the configurations, please read Configure backup


Code Block
languagebash
titleSample Mysql restore command
bahmni -i <inventory_file_name> restore --restore_type=db --options=<DBName> --strategy=<dump/pitr> --restore_point=<Backup foldername>

Please replace the inventory_file_name with appropriate file name and DBName with the database name (either openmrs or bahmni_reports). For example, in the below examples local is the inventory file name. 

There are different configurations for mysql database backup command as mentioned below. Please note that there are no default values for the below configurations

KeyDescriptionMandatory
restore_type

Value should be "db" (in case of database restore)

Yes
optionsAvailable options for mysql database restore are "openmrs" or "bahmni_reports"Yes
strategy

Two types of strategies are available as explained below.

StrategyDescription
pitrIf the restore point value is the folder name of the backup.
dumpIf the restore point value is database entire dump gunzip file.


Yes
restore_point
  • Value should be folder name of the backup file(It could be either incr/full).
  • If the strategy is dump, then value should be dump file name.
Yes

Mysql Dump Restore

One can restore the database by providing dump gunzip file.

Code Block
languagebash
titleOpenmrs Database Dump Restore
bahmni -i local restore --restore_type=db --options=openmrs --strategy=dump   --restore_point=openmrs_dump_20170221084218.sql.gz

Mysql Full Restore

One can restore the database by providing full backup file.

Code Block
languagebash
titleOpenmrs Database FULL PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=openmrs --strategy=pitr   --restore_point=20170220103125_full 


Code Block
languagebash
titleBahmni Reports Database FULL PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=bahmni_reports --strategy=pitr   --restore_point=20170220103125_full 


Note

In above examples, please replace 20170220103125_full (in case of full restore) with appropriate backup folder name available in the configured restore path and local with relevant inventory file name.


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.

Mysql Incremental Restore

One can restore the database by providing incremental backup file.

Code Block
titleOpenmrs Database INCREMENTAL PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=openmrs --strategy=pitr   --restore_point=20170330103125_incr  


Code Block
titleBahmni Reports Database INCREMENTAL PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=bahmni_reports --strategy=pitr   --restore_point=20170330103125_incr  


Note

In above examples, please replace 20170330103125_incr (in case of incremental restore) with appropriate backup folder name available in the configured restore path and local with relevant inventory file name.


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.

Pgsql Database Backup:

Warning

In this approach of taking backup of postgres database, we can't take individual postgres database backup (like clinlims or openerp).

There are different configurations for postgres database backup command as mentioned below

KeyDefault valueAvailable optionsMandatory
backup_typeallThis value should be db for database backupNo
optionsallThis Value can be either postgres while taking mysql pgsql database backup.No
strategyfull

Possible values are full, incr.

No

Postgres Full Backup

One can take full backup of particular postgres database by mentioning the database name under options which is postgres.

Code Block
languagebash
themeConfluence
titleSample command for Full backup of Postgres database
  bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName>

Please replace the inventory_file_name with appropriate file name and DBName with the database name (postgres). For example, in the below examples local is the inventory file name.

Code Block
languagebash
titlePostgres Databases Full Backup
bahmni -i local backup --backup_type=db --options=postgres 


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.

Postgres Incremental Backup:

Apart from the full backup, there is an option to take incremental backup. In case of incremental backup, strategy should be "incr"

Code Block
titleSample Command for Incremental Backup
bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName>  --strategy=incr

Please replace the inventory_file_name with appropriate file name and DBName with the database name. For example, in the below examples local is the inventory file name.

Code Block
languagebash
themeConfluence
titlePostgres Database Incremental Backup
  bahmni -i local backup --backup_type=db --options=postgres  --strategy=incr


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.

Pgsql Database Restore:

One can restore the entire pgsql backup at a time. In case of restoring an empty postgres database, first the db has to be restored using a full backup and then the desired incremental backup has to be applied on it.

Warning

In the newer way of restoring the pgsql backup, we can't restore individual databases (for elis and erp).


Code Block
languagebash
titlePgsql restore
bahmni -i <inventory_file_name> restore --restore_type=db --options=postgres --strategy=<pitr/dump>     --restore_point=<DB backup folder name>


There are different configurations for pgsql database backup command as mentioned below. Please note that there are no default values for the below configurations

KeyDescriptionMandatory
restore_type

Value should be "db" (in case of database restore)

Yes
options
  • value in case of pitr startegy is "postgres".
  • value in case of dump strategy is "clinlims" or "openerp".
Yes
strategy

Two types of strategies are available as explained below.

StrategyDescription
pitrIf the restore point value is the folder name of the backup.
dumpIf the restore point value is database entire dump gunzip file.


Yes
restore_point
  • Value should be folder name of the backup file(It could be either incr/full).
  • If the strategy is dump, then value should be dump file name.
Yes

Postgres Dump Restore

Please replace the inventory_file_name with appropriate file name. For example, in the below examples local is the inventory file name.

Openerp Dump Restore

One can restore the database by providing dump gunzip file.

Code Block
languagebash
titleOpenerp Database Dump Restore
bahmni -i local restore --restore_type=db --options=openerp --strategy=dump   --restore_point=openerp_dump_20170221084218.sql.gz

Openelis Dump Restore

Code Block
languagebash
titleOpenELIS (clinlims) Database Dump Restore
bahmni -i local restore --restore_type=db --options=openerp --strategy=dump   --restore_point=openerp_dump_20170221084218.sql.gz

Postgres Full Restore

One can restore the database by providing full backup file.

Code Block
languagebash
titlePostgres Database FULL PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=postgres --strategy=pitr  --restore_point=20170221-120904F


Note

In above examples, please replace 20170221-120904F (in case of full restore) with appropriate backup folder name available in the configured restore path and local with relevant inventory file name.


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.

Postgres Incremental Restore

One can restore the database by providing incremental backup file.

Code Block
titlePostgres Database Incremental PITR (Point In Time Restore)
bahmni -i local restore --restore_type=db --options=postgres --strategy=pitr   --restore_point= 20170221-121423F_20170222-124131I  


Note

In above examples, please replace  20170221-121423F_20170222-124131I(in case of incremental restore) with appropriate backup folder name available in the configured restore path and local with relevant inventory file name.


Warning

If the file is not available in the restore path, it is expected that the restore command will fail.


Artifacts Backup

We can either take backup of all artifacts or individual artifacts. There are different configurations available as listed below

KeyDescriptionMandatory
backup_typeThis Value should be "file" incase of artifact backupyes
options

all available values are listed below

ValueDescription
allbackup all artifacts
patient_imagesbackup patient images only
document_imagesbackup document images only

uploaded-files

backup uploaded files only

uploaded_results

backup uploaded results only
reportsbackup reports only
pacs_imagesbackup pacs images only


yes

Artifacts Full Backup

Please replace local with appropriate inventory file name. For example, in the below examples local is the inventory file name.

Code Block
titleCommand to backup all artifacts
bahmni -i local backup --backup_type=file  --options=all 

Artifacts Individual/Specific Backup

Please replace the inventory_file_name with appropriate file name and artifact_name with the relevant value. 

Code Block
languagebash
themeConfluence
titleBackup specific files
bahmni -i <inventory_file_name> backup --backup_type=file  --options=<artifact_name>


Code Block
titleCommands to Backup specific files
bahmni -i local backup --backup_type=file  --options="patient_images" //for patient images
bahmni -i local backup --backup_type=file  --options="document_images" //for document images
bahmni -i local backup --backup_type=file  --options="uploaded-files" //for uploaded files
bahmni -i local backup --backup_type=file  --options="uploaded_results" //for uploaded results
bahmni -i local backup --backup_type=file  --options="reports" //for reports
bahmni -i local backup --backup_type=file  --options="pacs_images" //for pacs images 


Warning

Backing up multiple artifacts (giving comma separated values without using all) is not supported right now. But, this can be achieved with a custom script with all the individual/specific backup commands.


Artifacts Restore

We can either restore all artifacts or individual artifacts.There are different configurations available as listed below

KeyDescriptionMandatory
restore_typeThis Value should be "file" incase of artifact restoreyes
options

all available values are listed below

ValueDescription
allrestore all artifacts
patient_imagesrestore patient images only
document_imagesrestore document images only

uploaded-files

restore uploaded files only

uploaded_results

restore uploaded results only
reportsrestore reports only
pacs_imagesrestore pacs images only


yes

Artifacts Full Restore

Please replace local with appropriate inventory file name. For example, in the below examples local is the inventory file name.

Code Block
titleCommand to restore all artifacts
bahmni -i local restore --restore_type=file  --options=all 


Artifacts Individual/Specific Restore

Please replace the inventory_file_name with appropriate file name and artifact_name with the relevant value. 

Code Block
languagebash
themeConfluence
titleRestore specific files
bahmni -i <inventory_file_name> restore --restore_type=file  --options=<artifact_name>


Code Block
titleExample Commands to Restore specific files
bahmni -i local restore --restore_type=file --options="patient_images" //for patient images
bahmni -i local restore --restore_type=file  --options="document_images" //for document images
bahmni -i local backup --restore_type=file  --options="uploaded-files" //for uploaded files
bahmni -i local restore --restore_type=file  --options="uploaded_results" //for uploaded results
bahmni -i local restore --restore_type=file  --options="reports" //for reports
bahmni -i local restore --restore_type=file  --options="pacs_images" //for pacs images 




Tip
titleOn this Page

Table of Contents


Panel
titleColorwhite
titleBGColor#668D3C
titleFeature Details

Feature Guide


Panel
titleColorwhite
titleBGColor#668D3C
titleImplemnentation Details

Implementer's Guide


Panel
titleRelated Links

Discussion on Backup/Restore tool (OpenMRS Talk)