################################################################### Резервное копирование и восстановление базы данных Promuc FrameWork ################################################################### .. contents:: :depth: 4 Создание дампа базы данных ========================== 1. Останавливаем сервис FrameWork .. code-block:: shell cd /opt/promuc ./do.sh framework down 2. Создаём дамп .. code-block:: shell docker exec -i postgres pg_dump -U postgres -d framework -Fc -v --no-owner --no-privileges --no-tablespaces > dump.sql 3. Запускаем сервис FrameWork .. code-block:: shell ./do.sh framework up -d Восстановление дампа базы данных ================================ .. warning:: Восстановление данным способом выполняется в рамках аналогичной версии docker-образа сервиса ``postgres`` 1. Останавливаем сервис FrameWork .. code-block:: shell cd /opt/promuc ./do.sh framework down 2. Удаляем и создаём базу данных: .. code-block:: shell docker exec postgres dropdb -U postgres framework docker exec postgres createdb -U postgres -O framework framework 3. Подготавливаем базу данных к восстановлению .. code-block:: shell docker exec postgres psql -U postgres -d framework -c "SELECT timescaledb_pre_restore();" 4. Восстанавливаем базу данных - если дамп базы данных был выгружен с параметром ``-Fc``: .. code-block:: shell docker exec -i postgres pg_restore -U postgres -d framework -Fc -v --no-owner --no-privileges < dump.sql - если дамп базы данных был выгружен в текстовом формате, без параметра ``-Fc``: .. code-block:: shell docker exec -i postgres psql -U postgres framework < dump.sql 5. Меняем владельца таблиц и последовательностей в схеме ``public`` .. code-block:: shell for tbl in `docker exec -i postgres psql -U postgres -d framework -qAt -c "select tablename from pg_tables where schemaname = 'public';"` ; do docker exec -i postgres psql -U postgres -d framework -c "alter table \"$tbl\" owner to framework"; done for tbl in `docker exec -i postgres psql -U postgres -d framework -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';"` ; do docker exec -i postgres psql -U postgres -d framework -c "alter sequence \"$tbl\" owner to framework"; done 6. Завершаем восстановление .. code-block:: shell docker exec postgres psql -U postgres -d framework -c "SELECT timescaledb_post_restore();" 7. Запускаем сервис FrameWork .. code-block:: shell ./do.sh framework up -d 8. Перезапускаем сервис Gitea .. code-block:: shell ./do.sh gitea up -d --force-recreate