Restore old installation of ERPNext into new instance

I had a v13 ERPNext running on my server. I crashed the server, deleted some files accidentally and had a hard time trying to restore it. Luckily I had taken a full backup of the site with:

bench backup --with-files

I downloaded the backups into my local computer and clean wiped the server, installed fresh Ubuntu 20.04. I followed this link to install fresh Frappe app.

I have installed frappe successfully with:

bench init /home/sammy/frappe-bench --frappe-path GitHub - frappe/frappe: Low code web framework for real world applications, in Python and Javascript --frappe-branch version-13 --python python3

Now my next step (if I wanted a fresh ERPNext) would be:

bench get-app erpnext GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP) --branch version-13

and then

bench new-site your_domain --admin-password ‘erpnext_admin_password’ --mariadb-root-username sammy --mariadb-root-password ‘mariadb_password’

followed by:

bench --site your_domain install-app erpnext
bench start

But since I need the older instance, ( I have downloaded a backup of older instance. Backup was generated by bench backup --with-files)

How can I successfully restore my old installation with files, sql, database keeping in mind the database name, pwd, etc into the new installation ?

Is it safe to follow example 1 of this link ?

I found a lot of similar previous questions but none explains at what point I should import the old installation files.

Is this the correct method ?

I also found this one:

I need a suggestion on these steps so that everything works like the old installation.

First of all, your post claims that you crashed a v13 server but that you had a backup taken from it done with files.

Then you claim to be installing a v12 system to replace the v13 one that you crashed.

Well, the ERPNext/Frappe system can in fact migrate data from v12 to v13 fairly well, but there has NEVER been a version that allows you to migrate from v13 backwards to v12.

The patch files do not work that way.

If you need to replace your crashed v13 server, then create another v13 fresh install. Once you have that you can restore your database backup (with files) and then migrate the data up to whatever the latest point version of v13 might be.

This process does not work backwards in versions.

(Or it is possible that I am just not understanding your situation)

BKM

I first took backup with files. Then when trying to make some changes, I crashed the v13 server.

My bad. I installed a v13 server not v12. [ typo in the original post. now corrected. ]

I am not trying to migrate. [ it must be a confusion created by my typo. ]

I am trying to achieve this. I already installed a fresh Frappe. Next step is to install ERPNext.
Which method should I follow ?

Method A
Complete ERPNext fresh installation.
Then copy old backup files inside public and private file locations.
Then replace database.

or,

Method B
Install Frappe.
bench get-app erpnext …
Copy old backup files and database/sql.
bench new-site …

I am confused in this workflow. Please suggest correct method.

Use Method A

This is the best route because from the time you first installed your original server to now there have likely been changes to the ERPNext version. These changes sometimes also mean database field or schema changes.

So follow Method A to get the cleanest possible new server.

Then:

  • Move in the private and public files
  • Restore the original database
  • Run bench migrate to make sure your old database is converted to include any new additions or changes.
  • Remember to copy the “encryption key” from the original site_config.json to the new site_config.json. Forgetting to do this will likely prevent you from ever getting email to work again.

Hope that helps…

BKM

This worked. Thank you for your suggestions.

I have one question.
During installation, I ran mysql_secure_installation. When it asked to set root password I said Yes and typed in root password (say “ABCD1234”)

Now during restore, I used this command:

bench --site {site} restore {path/to/database/file} --with-public-files {path/to/public/archive} --with-private-files {path/to/private/archive}

It prompted for root password. When I entered “ABCD1234” it did not work. I had to use another user and its password. Again when I try to secure mysql installation by mysql_secure_installation it asks for root password. Entering “ABCD1234” gives

Access denied for user ‘root’@‘localhost’.

What is the issue with root password ? It has happened alot of times.

It is not easy to tell what may be happening there. I setup 4 new servers this morning and typed in my typical root password for all of them and they all worked.

One thing that “may” be going on is the password you selected may not be acceptable as a secure password. I always use a very secure password and have never had a problem with the secure mysql setup.

Hope this helps…

BKM

I don’t think that’s the issue.
Could it be because by default root used unix_socket and not mysql_native_password ?

I changed the plugin for root to mysql_native_password and now I don’t have that problem anymore.

Since I started installing ERPNext onto Ubuntu 20.04 I’ve never been able to use root as the mariadb user.

For some reason sudo is required. Even if you try mysql -u root -p then your password you will likley get an access denied error.

To solve this create new user will all permissions and grant option. Ex.
CREATE USER erpnext@localhost IDENTIFIED BY 'ABCD1234';
GRANT ALL PRIVILEGES ON mydatabase.* TO erpnext@localhost WITH GRANT OPTION;

Then you can run your restore command
bench --site {site} restore {path/to/database/file} --with-public-files {path/to/public/archive} --with-private-files {path/to/private/archive} --mariadb-root-username erpnext --mariadb-root-password ABCD1234

2 Likes