mirror of
https://github.com/Hopiu/postgres-upgrade.git
synced 2026-03-16 22:20:24 +00:00
- Introduced `simple_postgres_upgrade.sh`, a script to streamline the PostgreSQL upgrade process within Docker containers, featuring backup, restore, and upgrade capabilities. - Includes a detailed `README.md` with usage instructions, options, and examples. - Provides a `CHANGELOG.md` to track changes and features of the script. - Licensed under MIT as outlined in `LICENSE` file. - Initial version set to `0.0.1`.
2.7 KiB
2.7 KiB
PostgreSQL Docker Upgrade Script
This script facilitates the upgrade process of a PostgreSQL instance running in a Docker container. It can perform backups, restores, and complete PostgreSQL upgrades between specified versions.
Features
- Backup Creation: Safely backup your current PostgreSQL database.
- Data Restoration: Restore your database from a backup.
- Version Upgrades: Upgrade PostgreSQL to a new version via Docker.
- Log Tracking: Track all operations and errors using a detailed log file.
- Progress Feedback: Receive feedback during long operations with progress spinners.
- Color-Coded Logs: Easily distinguish between info, warnings, and errors.
Prerequisites
- Docker and Docker Compose installed on your machine.
- A running PostgreSQL container managed with Docker Compose.
- Sufficient permissions to execute Docker commands and interact with local files.
Usage
./script.sh [OPTIONS] <from-version> <to-version>
Options
--backup-only <version>: Create a backup of the specified PostgreSQL version without performing an upgrade.--restore-only <version>: Restore your database from an existing backup of the specified version without performing an upgrade.--dry-run <from-version> <to-version>: Simulate a PostgreSQL upgrade without making any actual changes.--help: Display the help message.
Example Commands
-
Upgrade from PostgreSQL version 13 to 14:
./script.sh 13 14 -
Only create a backup of PostgreSQL version 13:
./script.sh --backup-only 13 -
Restore database from an existing backup of version 13:
./script.sh --restore-only 13 -
Simulate the upgrade from version 13 to 14 without performing any actions:
./script.sh --dry-run 13 14
File Locations
- Backups: Stored in
./postgres-upgrade/backups - Logs: Located at
./postgres-upgrade/upgrade.log
Logging
The script includes a logging function, which outputs messages in different colors to the console and writes them to a log file. The log contains timestamps, log levels (INFO, WARNING, ERROR, PROGRESS), and messages.
Error Handling
- The script stops execution (
set -e) on command failures, undefined variables, or pipe failures. - A trap function is used to catch errors and report the line number where an error occurs.
Notes
- Ensure that you have sufficient disk space for backups.
- The script assumes a Docker Compose setup managing the PostgreSQL container.
- A
docker-compose.ymlfile is expected in the script's directory for configuring PostgreSQL containers.
License
This script is licensed under the MIT License. See the LICENSE file for more information.