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

Support for PostgreSQL database #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Support for PostgreSQL database #19

wants to merge 3 commits into from

Conversation

mreho
Copy link

@mreho mreho commented Dec 22, 2024

Hello,

Here are some changes for PostgreSQL support.

I only copied the localtos3.php file to a new one, and adapted the queries for PostgreSQL, as well as backup system.

This is not the cleanest way to do this obviously, but as it act as a one-shot tool I didn't want to burn to much gaz on it :)

Tested and working perfectly on my Nextcloud installation (v30.0.4, 25 users, 3 TB data to migrate).

Enjoy !

@neil-lcv-cs
Copy link

neil-lcv-cs commented Jan 7, 2025

Hi there,

I’ve used your script to successfully migrate our storage from local to S3. Thanks!
Here’s our setup characteristics:

  • Docker image nextcloud:30-fpm, latest version
  • 100 users, ~5GB disk storage
  • PostgreSQL 16
  • PHP 8.2.27 (as used by the official Docker image)
  • Using the nobody user for the FPM process

I had to tweak the script to make it work, though. Here’s the list of changes I made:

  • Set the PATH_BASE variable correctly. In the official Docker image, the path of Nextcloud is /var/www/html/, thus PATH_BASE is /var/www/.
  • OCC_BASE uses php instead of php8.3. The official Docker image only ships this binary.
  • The autoload file is located at /lib/composer/autoload.php instead of /vendor/autoload.php. There is no vendor folder in the Docker image.
  • Had to edit the occurrences of $CONFIG['dbhost'] in the script; we are using a custom port for PostgreSQL and pg_connect() doesn’t support a hostname using the IP:PORT syntax. Replaced with host=IP port=IP.
  • Similar edit for the pg_dump command using -h $CONFIG['dbhost'] ; changed to -h IP -p PORT.

I had to enter the following commands too.

As root:

apt update
apt install -y libpq-dev
docker-php-ext-install pgsql

# workaround for postgres client in Bookworm shipped with version 15, while our server is using PGSQL 16
echo "deb https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt install -y gnupg
curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt install postgresql-client-16

# workaround: composer is not shipped in the Docker image
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Then, as a regular user:

composer require aws/aws-sdk-php
php -d memory_limit=1024M /var/www/html/localtos3-postgres.php

I have created and configured the backups folder beforehand.

EDIT: Forgot to mention, one of our users had a single quotation mark ' in their Nextcloud ID, it broke the script. Had to delete the user before proceeding.

Hope it’ll help!

@mreho
Copy link
Author

mreho commented Jan 7, 2025

Hey, glad to hear that it could help the community :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants