Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI database backup and restore #6387

Merged
merged 6 commits into from
Apr 30, 2024
Merged

Conversation

Alkarex
Copy link
Member

@Alkarex Alkarex commented Apr 27, 2024

Can also be used to migrate from one database to another (e.g. MySQL to PostgreSQL) or to ease upgrade to a major PostgreSQL version (e.g. 15 to 16).

My use-case is that PostgreSQL does not support easy migration to newer major versions, especially not when using Docker docker-library/postgres#37

Instructions assuming a Docker Compose structure like https://github.com/FreshRSS/FreshRSS/tree/edge/Docker/freshrss but can be adapted to other Compose structures or basic Docker (without Compose).

# Stop FreshRSS container (Web server + cron) during maintenance
docker compose down freshrss

# Optional additional pre-upgrade back-up using PostgreSQL own mechanism
docker compose -f docker-compose-db.yml \
  exec freshrss-db pg_dump -U freshrss freshrss | gzip -9 > freshrss-postgres-backup.sql.gz
# ------↑ Name of your PostgreSQL Docker container
# -----------------------------↑ Name of your PostgreSQL user for FreshRSS
# --------------------------------------↑ Name of your PostgreSQL database for FreshRSS

# Back-up all users respective database to SQLite files
docker compose -f docker-compose.yml -f docker-compose-db.yml run --rm freshrss cli/db-backup.php

# Remove old PostgreSQL container and PostgreSQL data volume
docker compose -f docker-compose-db.yml down --volumes freshrss-db

# Edit your Compose file to use latest postgres:xx
nano docker-compose-db.yml

# Start new PostgreSQL container and new empty PostgreSQL data volume
docker compose -f docker-compose.yml -f docker-compose-db.yml up -d freshrss-db

# Restore all users respective database from SQLite files
docker compose -f docker-compose.yml -f docker-compose-db.yml \
  run --rm freshrss cli/db-restore.php --delete-backup

# Restart a new FreshRSS container after maintenance
docker compose -f docker-compose.yml -f docker-compose-db.yml up -d freshrss

Can also be used to migrate from one database to another (e.g. MySQL to PostgreSQL) or to ease upgrade to a major PostgreSQL version (e.g. 15 to 16).
@Alkarex Alkarex added the CLI Command line interfaces in ./cli label Apr 27, 2024
@Alkarex Alkarex added this to the 1.24.0 milestone Apr 27, 2024
@Alkarex Alkarex marked this pull request as ready for review April 27, 2024 16:29
@Alkarex
Copy link
Member Author

Alkarex commented Apr 27, 2024

* [ ] I lack a mutex

Using the approach of stopping the FreshRSS service instead, during maintenance

@@ -259,15 +272,18 @@ public function dbCopy(string $filename, int $mode, bool $clearFirst = false): b
$error = 'Error: SQLite import file is not readable: ' . $filename;
} elseif ($clearFirst) {
$userDAO->deleteUser();
$userDAO = FreshRSS_Factory::createUserDao();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix regression from #6285 for some cases

@Alkarex Alkarex merged commit 329fd4b into FreshRSS:edge Apr 30, 2024
2 checks passed
@Alkarex Alkarex deleted the cli-db-backup branch April 30, 2024 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Command line interfaces in ./cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant