Automatycznie update wersji ROBO

Jeśli mamy już gotową wersję ROBO możemy przystąpić do utworzenia automatycznej aktualizacji tej wersji. Auto aktualizacja wersji TEST / ROBO jest odtwarzana z wersji produkcyjnej z backupu dnia poprzedniego.

Do uruchomienia harmonogramu potrzebny nam będzie skrypt update_test, który umieszczamy w katalogu /etc/cron.daily.

#!/bin/bash
   
   DATE=$(date +"%Y%m%d")
   DST="/home/backup/db"
   OPTIONS="--force --ignore-errors --delete --delete-excluded \
       --exclude-from=/etc/backup/exclude_test.conf -a"
    DATESTART=$(date +"%Y-%m-%d %H:%M")
        echo "Start odtworzenie wersji ROBO ${DATESTART}"  >> /var/log/restore_robo_version.log



       su - postgres -c "psql -c \"SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'test' AND pid <> pg_backend_pid();\""

       su - postgres -c "dropdb test"
       su - postgres -c "createdb -O edokumenty test"
       su - postgres -c "gunzip -c $DST/edokumenty_${DATE}.sql.gz | psql test"

#Usunięcie konta ePUAP
sudo -u postgres -H -- psql -d  test -c "UPDATE epuap.entities SET is_del = true;"

#Usunięcie konfiguracji:
sudo -u postgres -H -- psql -d  test -c "delete from user_sys_conf where objnam ~* 'simpletable2/MOD_STATUS_LIST';"

rsync $OPTIONS /home/edokumenty/public_html/ /home/test/public_html/
rsync $OPTIONS /home/edokumenty/etc/ /home/test/etc/
rsync $OPTIONS /home/edokumenty/bin/ /home/test/bin/
rsync $OPTIONS /home/edokumenty/lib/ /home/test/lib/
rsync $OPTIONS /home/edokumenty/src/ /home/test/src/
rsync $OPTIONS /home/edokumenty/vendor/ /home/test/vendor/

cd /home/test/public_html/apps/edokumenty
vim -c '%s/dbname=edokumenty/dbname=test/' -c 'wq' config.inc
vim -c "%s/define(\'ROBO_VERSION\', FALSE)/define(\'ROBO_VERSION\', \'WERSJA TESTOWA AUTO\')/g" -c 'wq' config.inc
vim -c "%s/define(\'EXT_ACTIONS_ENGINE_URL\', \'https:\/\/edokumenty.eu\')/define(\'EXT_ACTIONS_ENGINE_URL\', \'https:\/\/edokumenty.eu\/test\')/g" -c 'wq' config.inc
vim -c "%s/define(\'APPLICATION_NAME\', \'Ready_™\')/define(\'APPLICATION_NAME\', \'WERSJA TESTOWA READY_™\')/g" -c 'wq' config.inc

cd /home/test/etc
vim -c '%s/edokumenty/test/' -c 'wq' env.toml


#Nadane uprawnień dla użytkownika test
cd /home/test/
chown -R test:test bin
chown -R www-data:test etc
chown -R test:test public_html
chown -R www-data:test public_html/apps/edokumenty/var
chmod -R g+rwX public_html/apps/edokumenty/var
chmod  g+s public_html/apps/edokumenty/var
chmod  g+s public_html/apps/edokumenty/var/img
chmod  g+s public_html/apps/edokumenty/var/tmp
chmod  g+s public_html/apps/edokumenty/var/tpl
chmod  g+w public_html/apps/edokumenty/var/tpl
chgrp -R test public_html/apps/edokumenty/var/cache
chmod -R g+rwX public_html/apps/edokumenty/var/cache
chown -R www-data:test public_html/apps/edokumenty/var/cache/tmpl
chmod  g+s public_html/apps/edokumenty/var/cache/tmpl
chown -R test:test src
chown -R test:test vendor

Ważne! Po automatycznym odtworzeniu bazy na ROBO należy sprawdzić czy w pliku config.inc baza z której ma korzystać system eDokumenty to test

define( 'DB_NAME','dbname=test  user=http  password= ');
define('ROBO_VERSION','WERSJA TESTOWA AUTO');

Zawartość pliku exclude_test.conf

/apps/edokumenty/var/log/*
/apps/edokumenty/var/tmp/*
/apps/backproc/data/*
/apps/backproc/logs/*
/apps/edokumenty/.config.inc.swp