Created
October 2, 2019 07:09
-
-
Save em230418/2f6ab1d1573ee2ee97c3259e153fab88 to your computer and use it in GitHub Desktop.
Скрипт для миграции odoo 8 на odoo 12 (недоработанный)
This file contains 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
#!/usr/bin/env bash | |
TMP_DIR=/home/noroot/tmp | |
OULIB_PATH=/home/noroot/Projects/c8/openupgradelib | |
OU9_PATH=/home/noroot/Projects/c8/ou9 | |
OU10_PATH=/home/noroot/Projects/c8/ou10 | |
OU11_PATH=/home/noroot/Projects/c8/ou11 | |
OU12_PATH=/home/noroot/Projects/c8/ou12 | |
ODOO10_PATH=/home/noroot/Projects/c10 | |
ODOO11_PATH=/home/noroot/Projects/c11 | |
ODOO12_PATH=/home/noroot/Projects/c12 | |
DBNAME=n1 | |
PG_DUMP9=/usr/bin/pg_dump | |
PG_DUMP11=/usr/lib/postgresql/11/bin/pg_dump | |
export PGPASSWORD='odoo' | |
mkdir -p $TMP_DIR | |
pip install virtualenv | |
function CI { | |
echo "----------------------" | |
echo $@ | |
echo "----------------------" | |
"$@" | |
} | |
function C { | |
echo "----------------------" | |
echo $@ | |
echo "----------------------" | |
"$@" | |
local status=$? | |
if [ $status -ne 0 ]; then | |
echo "error with $1" >&2 | |
exit $status | |
fi | |
return $status | |
} | |
# на всякий случай, закроем все эти докеры | |
docker stop odoo9 db-odoo9 | |
C cd $ODOO10_PATH | |
C docker-compose down | |
C cd $ODOO11_PATH | |
C docker-compose down | |
C cd $ODOO12_PATH | |
C docker-compose down | |
# клонируем последнюю версию openupgradelib | |
# и применяем патч к ней | |
if [ ! -d "$OULIB_PATH" ]; then | |
C git clone https://github.com/OCA/openupgradelib.git $OULIB_PATH | |
fi | |
cd $OULIB_PATH | |
C wget https://patch-diff.githubusercontent.com/raw/OCA/openupgradelib/pull/173.patch -O $TMP_DIR/173.patch | |
CI git apply $TMP_DIR/173.patch | |
# клонируем OpenUpgrade | |
# и создаем копии с разными версиями | |
if [ ! -d "$OU12_PATH" ]; then | |
C git clone --depth 1 --no-single-branch https://github.com/OCA/OpenUpgrade.git $OU12_PATH | |
fi | |
if [ ! -d "$OU9_PATH" ]; then | |
C cp $OU12_PATH $OU9_PATH | |
C cd $OU9_PATH | |
C git checkout 9.0 | |
fi | |
if [ ! -d "$OU10_PATH" ]; then | |
C cp $OU12_PATH $OU10_PATH | |
C cd $OU10_PATH | |
C git checkout 10.0 | |
fi | |
if [ ! -d "$OU11_PATH" ]; then | |
C cp $OU12_PATH $OU11_PATH | |
C cd $OU11_PATH | |
C git checkout 11.0 | |
fi | |
# создаем виртуальное окружение для ou9 и для ou10 | |
C cd $OU9_PATH | |
if [ ! -d "ou9_venv" ]; then | |
C virtualenv -p /usr/bin/python ou9_venv | |
fi | |
C source ou9_venv/bin/activate | |
pip freeze | grep odoo | |
if [ "$?" != "0" ]; then | |
C pip install . | |
C pip install $OULIB_PATH | |
C pip install -U pyyaml==3.13 | |
fi | |
# создаем виртуальное окружения для ou11 и ou12 | |
C cd $OU11_PATH | |
if [ ! -d "ou11_venv" ]; then | |
C virtualenv -p /usr/bin/python3 ou11_venv | |
fi | |
C source ou11_venv/bin/activate | |
pip freeze | grep odoo | |
if [ "$?" != "0" ]; then | |
C pip install . | |
C pip install $OULIB_PATH | |
fi | |
# запускаем базу из 8-ой версии, берем оттуда базы | |
if [ -f "$TMP_DIR/8_$DBNAME.sql" ]; then | |
true | |
else | |
C docker start db-odoo | |
ODOO8_HOST=`docker inspect db-odoo | grep '"IPAddress"' | head -n 1 | tr -d '",' | awk '{ print $2 }'` | |
C `$PG_DUMP9 -h $ODOO8_HOST -d $DBNAME -U odoo > $TMP_DIR/8_$DBNAME.sql` | |
C docker stop db-odoo | |
fi | |
# переносим базу ду | |
# ну теперь последовательно переносим базу | |
# запускаем 9-ый оду | |
C docker start db-odoo9 odoo9 | |
ODOO9_HOST=`docker inspect db-odoo9 | grep '"IPAddress"' | head -n 1 | tr -d '",' | awk '{ print $2 }'` | |
echo $ODOO9_HOST | |
# готовим параметры | |
OU_PARAMS="-d $DBNAME --db_host $ODOO9_HOST --db_port 5432 --db_user odoo --db_pass odoo --update all --stop-after-init --addons-path=contract,addons --log-sql" | |
PSQL_PARAMS="-h $ODOO9_HOST -p 5432 -d $DBNAME -U odoo" | |
PSQL_PARAMS_SUDO="-h $ODOO9_HOST -p 5432 -d postgres odoo" | |
RETRIES=5 | |
until psql $PSQL_PARAMS_SUDO </dev/null || [ $RETRIES -eq 0 ]; do | |
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..." | |
sleep 1 | |
done | |
# загружаем туда базу | |
echo "DROP DATABASE IF EXISTS $DBNAME; CREATE DATABASE $DBNAME OWNER odoo" | psql $PSQL_PARAMS_SUDO | |
psql $PSQL_PARAMS < $TMP_DIR/8_$DBNAME.sql | |
#psql $PSQL_PARAMS | |
# конвертируем из 8 до 9 | |
C cd $OU9_PATH | |
C source ou9_venv/bin/activate | |
./odoo.py $OU_PARAMS 2>&1 | tee $TMP_DIR/output_9_$DBNAME.log | |
if [ "${PIPESTATUS[0]}" -ne 0 ]; then | |
exit 1 | |
fi | |
echo "Press any key to continue" | |
read -n 1 | |
# останавливаем 9-ый оду | |
docker stop db-odoo9 odoo9 | |
# --------- | |
OU_PARAMS="-d $DBNAME --db_host localhost --db_port 5433 --db_user odoo --db_pass odoo --update all --stop-after-init --addons-path=contract,addons --log-sql" | |
PSQL_PARAMS="-h localhost -p 5433 -d $DBNAME -U odoo" | |
PSQL_PARAMS_SUDO="-h localhost -p 5433 -d postgres odoo" | |
# ----------------------------------------------------------- | |
# запускаем odoo10 | |
C cd $ODOO10_PATH | |
C docker-compose up -d odoo | |
# загружаем базу 9-ой версии | |
echo "DROP DATABASE IF EXISTS $DBNAME; CREATE DATABASE $DBNAME OWNER odoo" | psql $PSQL_PARAMS_SUDO | |
psql $PSQL_PARAMS < $TMP_DIR/9_$DBNAME.sql | |
# конвертируем из 9 до 10 | |
C cd $OU10_PATH | |
./odoo-bin $OU_PARAMS 2>&1 | tee $TMP_DIR/output_10_$DBNAME.log | |
if [ "${PIPESTATUS[0]}" -ne 0 ]; then | |
exit 1 | |
fi | |
exit 0 | |
# берем копию этой базы | |
C `$PG_DUMP11 $PSQL_PARAMS > $TMP_DIR/10_$DBNAME.sql` | |
# закрываем оду 10 | |
C cd $ODOO10_PATH | |
docker-compose down | |
# -------------------------------------------------------------- | |
# запускаем odoo11 | |
C cd $ODOO11_PATH | |
C docker-compose up -d odoo | |
# загружаем базу 10-ой версии | |
echo "DROP DATABASE IF EXISTS $DBNAME; CREATE DATABASE $DBNAME OWNER odoo" | psql $PSQL_PARAMS_SUDO | |
psql $PSQL_PARAMS < $TMP_DIR/10_$DBNAME.sql | |
# конвертируем из 10 до 11 | |
C cd $OU11_PATH | |
C source ou11_venv/bin/activate | |
./odoo-bin $OU_PARAMS 2>&1 | tee $TMP_DIR/output_11_$DBNAME.log | |
if [ "${PIPESTATUS[0]}" -ne 0 ]; then | |
exit 1 | |
fi | |
# берем копию этой базы | |
C `$PG_DUMP11 $PSQL_PARAMS > $TMP_DIR/11_$DBNAME.sql` | |
# закрываем оду 11 | |
C cd $ODOO11_PATH | |
С docker-compose down | |
# запускаем odoo12 | |
C cd $ODOO12_PATH | |
C docker-compose up -d odoo | |
# загружаем базу 11-ой версии | |
echo "DROP DATABASE IF EXISTS $DBNAME; CREATE DATABASE $DBNAME OWNER odoo" | psql $PSQL_PARAMS_SUDO | |
psql $PSQL_PARAMS < $TMP_DIR/11_$DBNAME.sql | |
# конвертируем из 11 до 12 | |
C cd $OU12_PATH | |
./odoo-bin $OU_PARAMS 2>&1 | tee $TMP_DIR/output_12_$DBNAME.log | |
if [ "${PIPESTATUS[0]}" -ne 0 ]; then | |
exit 1 | |
fi | |
echo OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment