Last active
September 16, 2018 14:18
-
-
Save YuyaKobayashi/1574e04d9c0ac735b263777a39b3adc7 to your computer and use it in GitHub Desktop.
backup script for https://www.orca.med.or.jp/receipt/use/rebld/rebld.html#copy2_0_3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| fin_err(){ | |
| errmsg=$@ | |
| if [[ -n "$errmsg" ]]; then | |
| sudo rm -fr $work_dir | |
| fi | |
| echo "$errmsg" >&2 | |
| sudo systemctl start jma-receipt | |
| } | |
| work_dir=$(mktemp -d) | |
| DBdump=$work_dir/DBdump | |
| # check if jma-receipt is running | |
| num_proc=$(ps ax | egrep -c 'glserver|monitor|glauth') | |
| if [[ "$num_proc" -gt 0 ]]; then | |
| # stop jma-recipt | |
| sudo systemctl stop jma-receipt | |
| fi | |
| # create dump file of DB | |
| sudo -u orca pg_dump -Fc orca > $DBdump | |
| if [[ "$?" == 0 ]]; then | |
| echo Contents in the DB is dumped into $DBdump | |
| else | |
| fin_err 'fail to create dump file of the DB' | |
| exit -1 | |
| fi | |
| # backup the configrations | |
| config_backup_dir=$work_dir/config/ | |
| mkdir -p ${config_backup_dir} | |
| sudo cp -rp /etc/jma-receipt $config_backup_dir | |
| if [[ "$?" == 0 ]]; then | |
| echo configration files are copied to $config_backup_dir | |
| else | |
| fin_err 'fail to take a backup of the configurations' | |
| exit -1 | |
| fi | |
| # finalization | |
| echo The backups are completed SUCCESSFULLY! \ | |
| Those are placed in $work_dir. | |
| sudo systemctl start jma-receipt | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment