elosys:windows_restore

Windows Restore Script

This script is designed to automate the process of restoring a PostgreSQL database and a filestore for an Odoo instance. It extracts the latest backups of the database, filestore, and extra-addons, decompresses them, and then restores the database while updating the admin password.

  • You can find the script on Gitlab .

Before running the script, ensure that the following prerequisites are met:

  • Backup Files: Have recent backups of the PostgreSQL database, filestore, and extra-addons for the Odoo instance. These backups should be stored in a designated directory.
  • Configuration File: Create a wrestore.conf file in the same directory as the script. This file should contain the necessary configurations in the format key=value.
  • WinRAR Installation: Ensure WinRAR is installed on the system, and the path to the WinRAR executable is correctly set in the WINRAR_PATH configuration.
  • PostgreSQL Access: Ensure that the PostgreSQL user specified in the configuration file (PG_USER) has the necessary permissions to drop and create databases, create roles, and perform other operations required by the script.
  • Database Role and Password: If the PostgreSQL role 'odoo' is used for the Odoo application, ensure it is set up with the appropriate permissions. Additionally, ensure the admin password (ADMIN_PASSWORD) is correctly set in the script for updating the admin password in the restored database.
  • Filesystem Permissions: Ensure that the user running the script has appropriate permissions to access and modify the Odoo installation directory, backup directory, and any other relevant directories.
  • The script begins by loading configurations from the wrestore.conf file. This file contains key-value pairs in the format key=value representing various configurations needed for the restoration process. The configurations include:
    • PG_PASSWORD: PostgreSQL password.
    • BACKUP_DIR: Directory containing backup files.
    • ODOO_DIR: Directory where the Odoo instance is installed.
    • PG_BIN: Path to the PostgreSQL binaries.
    • PG_USER: PostgreSQL user.
    • PG_DBNAME: Name of the PostgreSQL database.
    • FILESTORE_DIR: Directory where the filestore backup is stored.
    • WINRAR_PATH: Path to the WinRAR executable.
  • The script displays the loaded configurations for debugging purposes. It confirms the configurations loaded from the wrestore.conf file.
  • The script checks if WinRAR is installed at the specified path. If WinRAR is not found, the script exits with an error code.
  • The script identifies the latest backup files for extra-addons, filestore, and database by searching for specific patterns in the backup directory (BACKUP_DIR). It sets variables LATEST_ADDONS, LATEST_FILESTORE, and LATEST_DATABASE to the names of the latest files.
  • The script displays the names of the latest backup files found for confirmation and logging purposes.
  • If a latest extra-addons backup file is found (LATEST_ADDONS is not empty), the script proceeds to extract it. It first cleans the existing extra-addons directory, then extracts the backup file to the extra-addons directory of the Odoo instance.
  • The script defines the target directory for extracting the filestore backup (TARGET_DIR). It deletes the existing filestore directory if it exists and creates a new one.
  • The script extracts the filestore backup to the target directory.
  • The script checks if the PostgreSQL database exists. If it does, it drops the existing database and creates a new one with the same name (PG_DBNAME).

The script checks if the PostgreSQL role 'odoo' exists. If it doesn't, it creates the role with the login password 'odoo'.

The script decompresses the latest database backup file (LATEST_DATABASE) to a temporary location (temp_db_backup.sql).

The script restores the database from the decompressed SQL file.

The script changes the admin password in the restored database to the one specified in the configuration (ADMIN_PASSWORD).

The script deletes the temporary database backup file after restoration is complete.

Finally, the script indicates the completion of the restoration process.


— Nadir Habib 2024/04/26 17:37

  • elosys/windows_restore.txt
  • Last modified: 2024/04/26 17:39
  • by nadir