Skip to content

Instantly share code, notes, and snippets.

@YuyaKobayashi
Last active September 16, 2018 14:18
Show Gist options
  • Select an option

  • Save YuyaKobayashi/1574e04d9c0ac735b263777a39b3adc7 to your computer and use it in GitHub Desktop.

Select an option

Save YuyaKobayashi/1574e04d9c0ac735b263777a39b3adc7 to your computer and use it in GitHub Desktop.
#!/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