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:
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.
1. Configuration Loading
2. Displaying Loaded Configurations
3. Checking WinRAR Installation
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
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.
9. Checking and Creating Database
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