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.
Link
- You can find the script on Gitlab .
Prerequisites
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.
1. Configuration Loading
- 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.
2. Displaying Loaded Configurations
- The script displays the loaded configurations for debugging purposes. It confirms the configurations loaded from the wrestore.conf file.
3. Checking WinRAR Installation
- The script checks if WinRAR is installed at the specified path. If WinRAR is not found, the script exits with an error code.
4. Finding Latest Backup Files
- 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.
5. Displaying Latest Backup Files
- The script displays the names of the latest backup files found for confirmation and logging purposes.
6. Extracting Extra Add-ons
- 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.
7. Defining Target Directory for Filestore Extraction
- 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.
8. Extracting Filestore Backup
- The script extracts the filestore backup to the target directory.
9. Checking and Creating Database
- 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).
10. Checking and Creating PostgreSQL Role
The script checks if the PostgreSQL role 'odoo' exists. If it doesn't, it creates the role with the login password 'odoo'.
11. Decompressing Database Backup
The script decompresses the latest database backup file (LATEST_DATABASE) to a temporary location (temp_db_backup.sql).
12. Restoring Database
The script restores the database from the decompressed SQL file.
13. Changing Admin Password
The script changes the admin password in the restored database to the one specified in the configuration (ADMIN_PASSWORD).
14. Cleanup
The script deletes the temporary database backup file after restoration is complete.
15. Completion
Finally, the script indicates the completion of the restoration process.
— Nadir Habib 2024/04/26 17:37