domingo, 24 de julio de 2022

Avast Business "On-Premise" Console failed to update on Windows Server 2012, database lost. How to restore automatic backup.

I just updated Avast Business On Premise Console on Windows 2012 R2 Standard.

From version 7.29.911.54 (functional) to 7.29.990, due to Update banner on console.

The update failed to install VC 2015 (noticed VC error message) but Avast installer "finished ok".
The updater created a backup on "C:\ProgramData\AVAST Software\Management Console\backup".

After the "update", I was unable to enter console with browser, start Avast Console service.

The new update, on Windows Server 2012 R2, if using VC 2015, requires KB2919335 (which requires KB2919442). I installed the KBs, restarted Windows Server, Avast console still unable to start.
There is no repair option on Avast Console option on Control Panel, had to reinstall (because previous upgrade was not ok).

But, after reinstall, the browser loaded a "create account page", no clue how to login with my email as before update.


Tried Avast's support for weeks, sent my case to "senior support", waste of time.

This Console uses PostgreSQL. Apparently, the Avast installer generates random password each time, so there is no default password at all.

So, the upgrade failed, the database was damaged/overwritten, unable to enter Management Console and the Avast server was not working at all.

The new installer replaced a very important file: "C:\Program Files\AVAST Software\Management Console\console\config\application-user-config.yml"

Inside that file are 2 fields: dbUsername and dbPassword. The original dbPassword was lost during failed update.


STEPS TO RECOVER

- Copy the backup folder created automatically by the updater ("C:\ProgramData\AVAST Software\Management Console\backup") to other location, just in case.

- Uninstall "Avast Business Management Console ..." from Control Panel / Programs and Features.

- Make sure you installed KB2919442 and  KB2919335.

- Install "Avast Business Management Console".

- Launch Console. You'll need to create your account (again) despite already existing.

- Once you get the empty Console / Dashboard, you may proceed with restore the backup created by installer. 

- First, we need to change the "postgres" account password on PostgreSQL Database Engine, installed with Avast Management Console. Go to folder "C:\ProgramData\AVAST Software\Management Console\data" and look for file pg_hba.conf (make a copy there -select file, Copy and Paste-, just in case).

- Edit pg_hba.conf, near the end of file, it may look like:




- You need to change all "Method" column, from "md5" to "trust" (without quotes), or just the first two lines corresponding to IPv4 and IPv6:



This is to allow reset main "Super User" postgres.

- Restart "Avast Business Management Console PostgreSQL" service (on Start / Administrative Tools / Services). It warns about "Avast Business Management Console" service will restart too, just choose Yes. Restart of service is required to get your changes.

- Once restarted, you may now connect to the PostgreSQL Database Engine. Open a Command Prompt window, and then go to folder: "C:\Program Files\AVAST Software\Management Console\PostgreSQL\bin" with the CD -change dir- command, space, and path (path quoted):

CD  "C:\Program Files\AVAST Software\Management Console\PostgreSQL\bin"

- Now use the PSQL program to connect to Database Engine on Command Prompt window, parameter -U is in uppercase:

    psql -U postgres


PostgreSQL will not require a password to login now.

- Execute the following command to set a new password for the Postgres user:

    ALTER USER postgres WITH PASSWORD 'new_password';


Remember the new password you use for postgres.

Exit the PostgreSQL command prompt with command: \q

- Restore the pg_dba.conf file (revert changes from trust to md5), restart the PostgreSQL database server and connect to the PostgreSQL database server with the new password.

- Now, we'll make a backup of the empty Avast Management Console, just to get the MD5 hashed passwords. On Command Prompt window still on "C:\Program Files\AVAST Software\Management Console\PostgreSQL\bin", execute the following command (please ensure folder C:\Tmp exists first):

    pg_dumpall.exe -U postgres -c -f  C:\tmp\dump.sql



This will create a backup of current empty Avast Console's database. If you installed Avast Console to use a non default Database TCP port, you'll need to add the option -p DB_PORT (where DB_PORT is the number of assigned TCP/IP port for PostgreSQL Database Engine on Avast Console). The example shows default port 5432.

- Edit the backup dump.sql with Notepad++ or any other text editor. Look for section "Roles" and copy to clipboard the SQL code used to create "bconsole" and "postgres", look for something like this (md5 hashes are for current "bconsole" and "postgres" passwords, your md5 hashes will be different):



- Edit the old backup file (make sure you have a copy of the backup on other folder), the one created automatically by Avast Console installer when failed upgrade (in my case, was on "C:\ProgramData\AVAST Software\Management Console\backup\database.dump"). Look for the same SQL code on "Roles" section. Select that code and delete it. Then Paste from clipboard the SQL code (copied previously from dump.sql file).

- Save the modified old backup file "database.dump" to C:\Tmp

- Stop service "Avast Business Management Console" (not the one with PostgreSQL on name).

- Restore the old backup, just modified, on Command Prompt window, still on "C:\Program Files\AVAST Software\Management Console\PostgreSQL\bin":

    psql -U postgres -f C:\Tmp\database.dump



When asked for postgres password, just enter the one you choose when changed it. 

The restore process begins and ends with no user intervention.

- Once restore is complete (a few seconds), start service "Avast Business Management Console" and try to open the Avast Business On Premise Management Console as usual. If any error, wait for about 20 seconds and then restart the "Avast Business Management Console" service.