V13 to v14 Upgrade Script - want that for every major version

Dear Community
I am using erpnext for many years now and every major version change the update procedure is not really thought through and many users are left on the road with old versions.

It would be really nice if a major version update script would be provided in the future, so that having a up-to-date ERPNext is hassle free.

After several unsuccessful tries in the last months I finally managed to make a sort-of script to update v13 to v14. It is not the best one and not all-in-one, but I tested the workflow a couple of times and it was working for me. Hopefully someone can find use of it.

I wish in the future a easy all-in-one-script would cover the following:

  1. Shows a path for the user with interactive entries like:
    • Do you want to update your instance to the latest version
    • what is your frappe user (to auto change user in the workflow)
    • what is your erpnext site Name
    • do you have customizations on frappe/erpnext files you want to keep (a function which handles this would be a charm)
    • and maybe something like extended and simple upgrade with more and less promts
  2. Checks for all dependencies on the instance and updates them accordingly
  3. Updates also the system if e.g. Ubuntu 22.xx is required
  4. Updates ERPNext and frappe
  5. Gives questions if system is working and proposes fixes

As a update strategy I did not do the testing on a live instance of course and for this I cloned the live instance. Problem with this is that the nginx needs to be reset to make it available through the ip. So for testing the script I would recommend to run the following to deactivate the https and reset the nginx to functionality can be testet easily:

bench config dns_multitenant off
bench setup nginx
sudo service nginx reload

##Now the step by step for v13 to v14 Update:

##1. Update NODEJS
run as root

curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt -y install nodejs
node -v

##2. Update Python to 3.10 and snyk

run as root

sudo apt install software-properties-common curl g++ -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10 python3.10-dev python3.10-distutils

run as frappe user in frappe-bench directory to assign python version to frappe

mv env env-old
virtualenv --python python3.10 env
env/bin/pip install -U pip
env/bin/pip install -e apps/frappe -e apps/erpnext
bench update --reset
rm -rf env-old
bench setup supervisor
bench restart --supervisor
bench update --requirements

Thanks @rmeyer How to upgrade to python 3.10

run as root to update/install snyk

npm install snyk -g

##3. Upgrade ERPNext SCRIPT
Create a erpupdate.sh file and run it with sh erpupdate.sh as frappe user
I noticed that apps are making quite many problems on updating a major versions
So I made a uninstall and remove-app section where you can add as many lines of apps

#!/bin/bash

echo "$(tput setaf 1)$(tput setab 7)--------------STARTING ERPNEXT v13 to v14 UPGRADE SCRIPT--------------$(tput sgr 0)"

read -p "Are you running this script as the designated frappe/erpnext system user (e.g. frappe)? (yes/no) " yn

case $yn in
	yes ) echo ok, we will proceed;;
	no ) echo exiting - please login with your designated frappe user and run the script again...;
		exit;;
	* ) echo invalid response;
		exit 1;;
esac

read -p "Are you running this script inside the frappe-bench direcotry? (yes/no) " yn

case $yn in
	yes ) echo ok, we will proceed;;
	no ) echo exiting - please navigate to the frappe-bench directory with your designated frappe user...;
		exit;;
	* ) echo invalid response;
		exit 1;;
esac

read -p "Do you have any customizations made on the erpnext/frappe files you want to keep? (yes/no) " yn

case $yn in
	no ) echo ok, we will proceed;;
	yes ) echo exiting - sorry this script cannot be used if you want to keep your modifications on files...;
		exit;;
	* ) echo invalid response;
		exit 1;;
esac

#get variables for UPDATE
echo "$(tput setaf 1)$(tput setab 7)ENTER YOUR SITE DETAILS$(tput sgr 0)"
echo What is your ERPNext Site-Name?
read SITENAME

#backup erpnext files and db
echo "$(tput setaf 1)$(tput setab 7)--------------Backing up your ERPNext Database and Files--------------$(tput sgr 0)"
bench backup --with-files

#uninstall apps
echo "$(tput setaf 1)$(tput setab 7)UNINSTALL APPS$(tput sgr 0)"
#bench --site $SITENAME uninstall-app NAMEOFYOURAPP

#remove apps
echo "$(tput setaf 1)$(tput setab 7)REMOVE APPS$(tput sgr 0)"
#bench remove-app NAMEOFYOURAPP

#update pip3
echo "$(tput setaf 1)$(tput setab 7)UPDATE PIP$(tput sgr 0)"
pip3 install frappe-bench --upgrade
pip3 -vvvv install --upgrade pyOpenSSL

echo "$(tput setaf 1)$(tput setab 7)...............FINALLY - UPGRADE ERPNEXT...............$(tput sgr 0)"
pip3 install frappe-bench --upgrade
bench update --reset
bench switch-to-branch version-14 --upgrade
bench get-app hrms
bench get-app payments
bench --site $SITENAME install-app hrms
bench --site $SITENAME install-app payments
bench migrate
bench update --reset
bench restart

echo "$(tput setaf 1)$(tput setab 7)-----------------------VISIT http://$SITENAME -----------------------$(tput sgr 0)"

read -p "Is the site working and online?" yn

case $yn in
	yes ) rm -rf env-old;;
	no ) echo please check the logs, fix what went wrong and repeat the process...;
		exit;;
	* ) echo invalid response;
		exit 1;;
esac

echo "$(tput setaf 1)$(tput setab 7)-----------------------UPDATE FINISHED -----------------------$(tput sgr 0)"
exit 0

##4. Update System if you are on a older Ubuntu Dist
create a systemupdate.sh and run it with sh systemupdate.sh as root

#!/bin/bash
#Update System in general
echo "$(tput setaf 1)$(tput setab 7)........STARTING UBUNTU SERVER UPDATE SCRIPT$(tput sgr 0)"
###########################################
read -p "Are you running this script as root? (yes/no) " yn

case $yn in
	yes ) echo ok, we will proceed;;
	no ) echo exiting - please change to root user and run the script again...;
		exit;;
	* ) echo invalid response;
		exit 1;;
esac

#update ubuntu system and software
echo "$(tput setaf 1)$(tput setab 7)UPDATE UBUNTU SYSTEM AND SOFTWARE$(tput sgr 0)"
###########################################
sudo apt-get update && apt-get -y upgrade
sudo apt autoremove -y
sudo apt clean
sudo apt autoclean
cd /etc/apt/sources.list.d
for i in *.list; do mv ${i} ${i}.disabled; done
sudo apt update
sudo apt upgrade -y
sudo apt dist-upgrade
sudo apt clean
sudo apt autoclean
sudo do-release-upgrade -f DistUpgradeViewNonInteractive
sudo apt-get update && apt-get -y upgrade
sudo apt --fix-broken install -y
sudo apt-get update && apt-get -y upgrade

#check and confirm update
echo "$(tput setaf 1)$(tput setab 7).......SYTEM UPDATED.......$(tput sgr 0)"
###########################################
echo "$(tput setaf 1)$(tput setab 7)UBUNTU VERSION$(tput sgr 0)"
lsb_release -cdr
echo "$(tput setaf 1)$(tput setab 7)NODEJS VERSION$(tput sgr 0)"
node -v
echo "$(tput setaf 1)$(tput setab 7)PYTHON VERSION$(tput sgr 0)"
python3 --version

read -p "You probably need to reboot your server, do you want to do it now? (yes/no) " yn

case $yn in
	no ) echo "$(tput setaf 1)$(tput setab 7)ok, please reboot as soon as possible before doing any more settings$(tput sgr 0)";
    exit 0;;
	yes ) echo system is rebooting, you will be logged out now.....;
		reboot;;
	* ) echo invalid response;
		exit 1;;
esac

I hope that worked for you and something like this will be provided on the dos or github.
Cause bench switch-to-branch version-14 --upgrade never did the trick in the past.

Of course some of you find it strange that I do the system update at last, but after many fails of doing it first I decided to get sure v14 is working with all requirements and then update the Ubuntu distro.

I usually wanted to to switch to a docker stack setup. But for this the database first needs to be in v14 state. Even than the restore does not work, so a doc on save restore on a docker environment would be really nice to have. Running bench restore backup.sql also never did the trick for me.

Hope this will help someone and inspire some future developments.
Have a nice day.

5 Likes

When reaching a working state on Ubuntu 22 and ERPNext v14 after running this, any bench command returns:

Traceback (most recent call last):
  File "/usr/local/bin/bench", line 33, in <module>
    sys.exit(load_entry_point('frappe-bench', 'console_scripts', 'bench')())
  File "/usr/local/bin/bench", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 969, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for frappe-bench

If you run

pip install frappe-bench

its working again.

1 Like

Thank you so much for this @pronext - I have been trying to upgrade from 13 to 14 for 6 months and finally got it to work with your guidance above!

1 Like