#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/bin
HOME=/home/Administrator
source ~/.bashrc

if [ -e "c:/backup_jm/kddm_jm.tar" ];
then
 psql -c 'delete from relations' kddm_jm
 psql -c 'delete from c_status' kddm_jm
 psql -c 'delete from r_status' kddm_jm
 psql -c 'delete from sys_config' kddm_jm
 psql -c 'delete from r_version' kddm_jm
 pg_restore -d kddm_jm -t relations c:/backup_jm/relations.tar
 pg_restore -d kddm_jm -t c_status c:/backup_jm/c_status.tar
 pg_restore -d kddm_jm -t r_status c:/backup_jm/r_status.tar
 pg_restore -d kddm_jm -t sys_config c:/backup_jm/sys_config.tar
 pg_restore -d kddm_jm -t r_version c:/backup_jm/r_version.tar
elif [ -e "$JM_ROOT_UNX/backup/kddm_jm.tar" ];
then
 psql -c 'delete from relations' kddm_jm
 psql -c 'delete from c_status' kddm_jm
 psql -c 'delete from r_status' kddm_jm
 psql -c 'delete from sys_config' kddm_jm
 psql -c 'delete from r_version' kddm_jm
 pg_restore -d kddm_jm -t relations $JM_ROOT_UNX/backup/relations.tar
 pg_restore -d kddm_jm -t c_status $JM_ROOT_UNX/backup/c_status.tar
 pg_restore -d kddm_jm -t r_status $JM_ROOT_UNX/backup/r_status.tar
 pg_restore -d kddm_jm -t sys_config $JM_ROOT_UNX/backup/sys_config.tar
 pg_restore -d kddm_jm -t r_version $JM_ROOT_UNX/backup/r_version.tar
fi
