Backup/Restore commands
About the Feature
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.
Right now Bahmni backup mechanism supports two categories name file backup and database backup. Below is the list of supported items
- Patient images
- Document images
- Uploaded files
- Uploaded lab results
- PACS images
- Report module generated files by Queue feature
- MySQL databases
- Postgres databases
Old Way of Backup and Restore
Old Way Backup
When the backup tools for MySQL and Postgres are not installed then the backup will fall back to 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.
bahmni -i local backup --backup_type=db --options=clinlimsbahmni -i local backup --backup_type=db --options=openerpbahmni -i local backup --backup_type=db --options=openmrsIf 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 -yOld Way Restore
Please replace the inventory_file_name with appropriate file name. For example, in the below examples local is the inventory file name.
bahmni -i local restore --restore_type=db --options=clinlims --strategy=dump --restore_point=clinlims_dump_20170215-150418.sql.gzbahmni -i local restore --restore_type=db --options=openerp --strategy=dump --restore_point=openerp_dump_20170215-150418.sql.gzbahmni -i local restore --restore_type=db --options=openmrs --strategy=dump --restore_point=openmrs_dump_20170221084218.sql.gzComplete / Full Backup
In order to backup all the possible files and databases, please use the below mentioned command.
bahmni -i <inventory_file_name> backup --backup_type=all --options=allPlease replace the inventory_file_name with appropriate file name. For Example, in the below example local is the inventory file name.
bahmni -i local backup --backup_type=all --options=allSchedule 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.
bahmni -i <inventory_file_name> backup --backup_type=<file/db> --options=<options_possible> --strategy=<strategy> --schedule "* * * * *"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 executedMysql Backup:
There are different configurations for mysql database backup command as mentioned below
| Key | Default value | Available options | Mandatory |
|---|---|---|---|
| backup_type | all | This value should be db for database backup | No |
| options | all | This Value can be either openmrs or bahmni-reports while taking mysql database backup. | No |
| strategy | full | Possible values are full, incr. | No |
Mysql Full Backup
One can take full backup of particular mysql database by mentioning the database name.
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.
bahmni -i local backup --backup_type=db --options=openmrsbahmni -i local backup --backup_type=db --options=bahmni_reportsMysql Incremental Backup:
Apart from the full backup, there is an option to take incremental backup. In case of incremental backup, strategy should be "incr"
bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName> --strategy=incrPlease 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.
bahmni -i local backup --backup_type=db --options=openmrs --strategy=incrbahmni -i local backup --backup_type=db --options=bahmni_reports --strategy=incrMysql Database Restore:
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.
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
| Key | Description | Mandatory |
|---|---|---|
| restore_type | Value should be "db" (in case of database restore) | Yes |
| options | Available options for mysql database restore are "openmrs" or "bahmni_reports" | Yes |
| strategy | Strategy | Description |
| pitr | If the restore point value is the folder name of the backup. | |
| dump | If the restore point value is database entire dump gunzip file. |
- 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.
Mysql Dump Restore
One can restore the database by providing dump gunzip file.
bahmni -i local restore --restore_type=db --options=openmrs --strategy=dump --restore_point=openmrs_dump_20170221084218.sql.gzMysql Full Restore
One can restore the database by providing full backup file.
bahmni -i local restore --restore_type=db --options=openmrs --strategy=pitr --restore_point=20170220103125_fullbahmni -i local restore --restore_type=db --options=bahmni_reports --strategy=pitr --restore_point=20170220103125_fullMysql Incremental Restore
One can restore the database by providing incremental backup file.
bahmni -i local restore --restore_type=db --options=openmrs --strategy=pitr --restore_point=20170330103125_incrbahmni -i local restore --restore_type=db --options=bahmni_reports --strategy=pitr --restore_point=20170330103125_incrPgsql Database Backup:
There are different configurations for postgres database backup command as mentioned below
| Key | Default value | Available options | Mandatory |
|---|---|---|---|
| backup_type | all | This value should be db for database backup | No |
| options | all | This Value can be either postgres while taking pgsql database backup. | No |
| strategy | full | 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.
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.
bahmni -i local backup --backup_type=db --options=postgresPostgres Incremental Backup:
Apart from the full backup, there is an option to take incremental backup. In case of incremental backup, strategy should be "incr"
bahmni -i <inventory_file_name> backup --backup_type=db --options=<DBName> --strategy=incrPlease 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.
bahmni -i local backup --backup_type=db --options=postgres --strategy=incrPgsql 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.
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
| Key | Description | Mandatory |
|---|---|---|
| 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 | Strategy | Description |
| pitr | If the restore point value is the folder name of the backup. | |
| dump | If the restore point value is database entire dump gunzip file. |
- 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.
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.
bahmni -i local restore --restore_type=db --options=openerp --strategy=dump --restore_point=openerp_dump_20170221084218.sql.gzOpenelis Dump Restore
bahmni -i local restore --restore_type=db --options=openerp --strategy=dump --restore_point=openerp_dump_20170221084218.sql.gzPostgres Full Restore
One can restore the database by providing full backup file.
bahmni -i local restore --restore_type=db --options=postgres --strategy=pitr --restore_point=20170221-120904FPostgres Incremental Restore
One can restore the database by providing incremental backup file.
bahmni -i local restore --restore_type=db --options=postgres --strategy=pitr --restore_point= 20170221-121423F_20170222-124131IArtifacts Backup
We can either take backup of all artifacts or individual artifacts. There are different configurations available as listed below
| Key | Description | Mandatory |
|---|---|---|
| backup_type | This Value should be "file" incase of artifact backup | yes |
| options | Value | Description |
| all | backup all artifacts | |
| patient_images | backup patient images only | |
| document_images | backup document images only | |
| uploaded-files | backup uploaded files only | |
| uploaded_results | backup uploaded results only | |
| reports | backup reports only | |
| pacs_images | backup pacs images only |
Artifacts Full Backup
Please replace local with appropriate inventory file name. For example, in the below examples local is the inventory file name.
bahmni -i local backup --backup_type=file --options=allArtifacts Individual/Specific Backup
Please replace the inventory_file_name with appropriate file name and artifact_name with the relevant value.
bahmni -i <inventory_file_name> backup --backup_type=file --options=<artifact_name>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 imagesArtifacts Restore
We can either restore all artifacts or individual artifacts.There are different configurations available as listed below
| Key | Description | Mandatory |
|---|---|---|
| restore_type | This Value should be "file" incase of artifact restore | yes |
| options | Value | Description |
| all | restore all artifacts | |
| patient_images | restore patient images only | |
| document_images | restore document images only | |
| uploaded-files | restore uploaded files only | |
| uploaded_results | restore uploaded results only | |
| reports | restore reports only | |
| pacs_images | restore pacs images only |
Artifacts Full Restore
Please replace local with appropriate inventory file name. For example, in the below examples local is the inventory file name.
bahmni -i local restore --restore_type=file --options=allArtifacts Individual/Specific Restore
Please replace the inventory_file_name with appropriate file name and artifact_name with the relevant value.
bahmni -i <inventory_file_name> restore --restore_type=file --options=<artifact_name>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 imagesBahmni Wiki · CC BY-SA 4.0