How to upgrade a NextCloud installation to use the new docker scripts

The docker scripts of nextcloud were rewritten recently. The new scripts are hopefully cleaner, more transparent, and more easy to understand. However it is not so obvious how to upgrade an existing nextcloud installation to use the new scripts. This is an attempt to explain it.

  1. Before trying anything, make a backup of the existing installation, just to be sure that things can be reverted if the upgrade procedure fails:

    cd /var/ds/nc.example.org/
    ds backup --nodata
    
  2. Fetch the latest version of the scripts:

    cd /opt/docker-scripts/nextcloud/
    git fetch
    git branch -a
    git checkout old
    
  3. Install a PostgreSQL container:

    ds pull postgresql
    ds init postgresql @postgresql
    cd /var/ds/postgresql/
    ds make
    
  4. Migrate the database from MariaDB to PostgreSQL and make a backup of it:

    cd /var/ds/nc.example.org/
    
    cat <<EOF >> settings.sh
    DB_HOST=postgresql
    DB_PORT=5432
    DB_NAME=nc_example_org
    DB_USER=nc_example_org
    DB_PASS=pass123
    EOF
    
    ds postgresql
    ds postgresql create
    
    ds shell
    apt install pgloader
    cat /host/settings.sh
    pgloader \
        mysql://nc_example_org:pass321@mariadb/nc_example_org \
        postgresql://nc_example_org:pass123@postgresql/nc_example_org
    exit
    
    ds postgresql dump > db.sql
    
  5. Remove the container and install a new one from scratch:

    cd /var/ds/nc.example.org/
    ds remove
    ds postgresql drop
    
    cd ..
    mv nc.example.org nc.example.org-old
    
    cd /opt/docker-scripts/nextcloud
    git checkout master
    
    ds init nextcloud @nc.example.org
    cd /var/ds/nc.example.org/
    vim settings.sh
    

    Make sure to copy ADMIN_USER, ADMIN_PASS and ADMIN_EMAIL from the old settings.sh to the new one.

    ds make
    
  6. Restore the content of the database and the data files from the old container:

    ds postgresql script ../nc.example.org-old/db.sql
    rsync -a --delete ../nc.example.org-old/www/data/ www/data/
    
    ds update
    ds occ files:scan --all
    ds update
    

    Note: If the directory www/data/ is mounted to an external volume, then instead of the rsync command above, something else needs to be done, accordingly.

  7. Clean up:

    cd /var/ds/
    rm -rf nc.example.org-old/
    
2 Likes