nextcloud / backup

Backup now. Restore later.
GNU Affero General Public License v3.0
248 stars 37 forks source link

Backup creation not possible when using different docker containers for NC and DB #175

Open opi1994 opened 2 years ago

opi1994 commented 2 years ago

Hi, I am using Nextcloud 23 with Backup App and Postgresql in different docker containers. So the Nextcloud Backup app has no access to the container Postgresql and can't run pg_dump: In SqlDumpPgSQL.php line 80: The dump process failed with exitcode 127 : Command not found : sh: 1: pg_dump: not found

Is it possible to resove this issue and keep seperated containers for NC and DB? If not please give us a hint in the documentation and in the webinterface (Error only visible using occ backup:point:create)

Maybe you could add a setting to ignore SQL Backup so i can dump SQL DB manually. Thanks

samuelcanadi commented 2 years ago

I have the same problem. Now I wonder which installation method is needed to be able to use the backup app.

Topkif commented 2 years ago

Exactly the same issue here, please what can we do?

packruler commented 2 years ago

Manually installing Postgres client does not resolve this issue either.

packruler commented 2 years ago

Correction, I installed the wrong version of the client, my Postgres container is on Postgres 14.2 and default Debain install version is 13.

I was able to get it working by updating the Dockerfile I use. Adding the following got the Postgres client package installed and the SQL dump worked fine.

# gnupg is a required for adding the Postgres key
RUN apt update && apt install -y gnupg
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null

# As of writing, NC is using `bullseye` and unable to install lsb-release with ease so hardcoded
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list

RUN apt-get update \
  && apt-get install -y \
    postgresql-client-14 \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* \
robeatoz commented 2 years ago

Thx @packruler, your Dockerfile helped me to create a Restoring Point with Postgres 14.2 database for Nextcloud

docker exec -it --user www-data nextcloud_nextcloud-server_1 /bin/bash
./occ backup:point:create

But when I tried to restore from a Restoring Point with

./occ backup:point:restore 20220406184132-full-vRZ3hsHKLWczxjx --do-not-ask-data --do-not-ask-sql

I had the following error messages:

   > importing sqldump in pgsql://nextcloud:****@nextcloud-postgres:/nextcloud: PHP extension 'pgsql' is missing. Please install first.
   > importing sqldump in pgsql://nextcloud:****@nextcloud-postgres:/nextcloud: PHP extension 'pgsql' is missing. Please install first.
   > importing sqldump in pgsql://nextcloud:****@nextcloud-postgres:/nextcloud: PHP extension 'pgsql' is missing. Please install first.
   > importing sqldump in pgsql://nextcloud:****@nextcloud-postgres:/nextcloud: PHP extension 'pgsql' is missing. Please install first.

I had to restart the container and turned off the maintenance mode manually.

To fix this, I have adjusted my Dockerfile:

FROM nextcloud:23.0.3-apache

# gnupg is a required for adding the Postgres key
RUN apt update && apt install -y gnupg
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null

# As of writing, NC is using `bullseye` and unable to install lsb-release with ease, so hardcoded
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list

# Install libpq-dev for PHP-Extension pgsql
# Install postgresql-client-14 and postgresql-dev for Backup-App
RUN apt-get update \
    && apt-get install -y  \
      libpq-dev \
      postgresql-client-14 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Package, damit die Backup-App über PHP mit Postgres sprechen kann.
# Siehe https://stackoverflow.com/questions/47603398/docker-php-with-pdo-pgsql-install-issue
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

Now, the restore command finishes:

+---------------------------+-----------+------------------------------------------------------+
| Data                      | Status    | Path                                                 |
+---------------------------+-----------+------------------------------------------------------+
| data                      | extracted | /var/www/html/data/                                  |
| nextcloud                 | extracted | /var/www/html/                                       |
| apps                      | extracted | /var/www/html/apps/                                  |
| config                    | extracted | /var/www/html/config/                                |
| apps-custom_apps-e76919dd | extracted | /var/www/html/custom_apps/                           |
| sqldump                   | imported  | pgsql://nextcloud:****@nextcloud-postgres:/nextcloud |
+---------------------------+-----------+------------------------------------------------------+

But my Nextcloud-Instance did not change. I created some new files, deleted existing ones and changed the theme color after the creation of the Restoring Point. All these changes are still there after executing

./occ backup:point:restore 20220406184132-full-vRZ3hsHKLWczxjx --do-not-ask-data --do-not-ask-sql

Well, one thing changed, my App-Passwords under Settings > Security > Devices & sessions are gone I used for the Nextcloud Password App and I had to create new ones.

Same behavior with MariaDB as database.

I have no clue what I did wrong and appreciate every hint!

mwLabs-eu commented 2 years ago

Hello,

any fix for this in the meanwhile? Same issue on 24.0.5 and Postgres as seperate docker

asciinaut commented 1 year ago

Hi, issue still exists on 25.0.4 and separate PostgreSQL.