-
Notifications
You must be signed in to change notification settings - Fork 11
Feat/nextcloud upgrade hooks #41
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /volumes | ||
| /backups | ||
| .env | ||
| docker-compose.override.yml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| run_occ() { | ||
| echo "Running: php occ $*" | ||
| php occ "$@" | ||
| } | ||
|
|
||
| echo "Running post-upgrade Nextcloud commands" | ||
| php occ app:list > /backups/app_list.new | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| if [ -f /backups/app_list.old ]; then | ||
| echo "Comparing app lists" | ||
| diff -u /backups/app_list.old /backups/app_list.new || true | ||
| fi | ||
| run_occ db:add-missing-columns | ||
| run_occ db:add-missing-indices | ||
| run_occ db:add-missing-primary-keys | ||
| run_occ maintenance:repair --include-expensive | ||
| run_occ config:system:set maintenance_window_start --type=integer --value=1 | ||
| run_occ app:update --all | ||
| run_occ maintenance:mode --off | ||
| echo "Post-upgrade commands completed successfully" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| nextcloud_dir=${NEXTCLOUD_DIR:-/var/www/html} | ||
| backup_dir=${NEXTCLOUD_BACKUP_DIR:-/backups} | ||
| min_free_mb=${NEXTCLOUD_UPGRADE_MIN_FREE_MB:-2048} | ||
| db_host=${POSTGRES_HOST:-postgres} | ||
| db_name=${POSTGRES_DB:-nextcloud} | ||
| db_user=${POSTGRES_USER:-nextcloud} | ||
| db_password=${POSTGRES_PASSWORD:-} | ||
| timestamp=$(date +%Y%m%d-%H%M%S) | ||
| backup_file="${backup_dir}/nextcloud-db-${timestamp}.sql.gz" | ||
| app_list_file="${backup_dir}/app_list.old" | ||
|
|
||
| run_occ() { | ||
| echo "Running: php occ $*" | ||
| php occ "$@" | ||
| } | ||
|
|
||
| check_free_space() { | ||
| local path=$1 | ||
| local label=$2 | ||
| local available_mb | ||
|
|
||
| available_mb=$(df -Pm "$path" | awk 'NR==2 { print $4 }') | ||
|
|
||
| if [ "$available_mb" -lt "$min_free_mb" ]; then | ||
| echo "Not enough disk space on ${label}: ${available_mb} MB available, ${min_free_mb} MB required" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "${label} has ${available_mb} MB free" | ||
| } | ||
|
|
||
| echo "Running pre-upgrade safety checks" | ||
| mkdir -p "$backup_dir" | ||
|
|
||
| run_occ maintenance:mode --on | ||
| php occ app:list > "$app_list_file" | ||
| echo "Saved active apps list to ${app_list_file}" | ||
|
|
||
| check_free_space "$nextcloud_dir" "Nextcloud volume" | ||
| check_free_space "$backup_dir" "Backup volume" | ||
|
|
||
| if ! command -v pg_dump >/dev/null 2>&1; then | ||
| echo "pg_dump is not available in the container image" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$db_password" ]; then | ||
| echo "POSTGRES_PASSWORD is empty, refusing to create a database dump" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Creating PostgreSQL dump at ${backup_file}" | ||
| PGPASSWORD="$db_password" pg_dump -h "$db_host" -U "$db_user" "$db_name" | gzip -9 > "$backup_file" | ||
| echo "Database dump completed successfully" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,25 @@ networks: | |
| driver: bridge | ||
|
|
||
| services: | ||
| redis: | ||
| image: redis:7-alpine | ||
| restart: unless-stopped | ||
| networks: | ||
| - internal | ||
|
|
||
| app: | ||
| build: | ||
| context: .docker/app | ||
| args: | ||
| NEXTCLOUD_VERSION: ${NEXTCLOUD_VERSION:-stable-fpm} | ||
| volumes: | ||
| - ./volumes/nextcloud:/var/www/html | ||
| - ./backups:/backups | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On a fresh checkout where Useful? React with 👍 / 👎. |
||
| - ./app-hooks/pre-installation:/docker-entrypoint-hooks.d/pre-installation | ||
| - ./app-hooks/post-installation:/docker-entrypoint-hooks.d/post-installation | ||
| - ./app-hooks/pre-upgrade:/docker-entrypoint-hooks.d/pre-upgrade | ||
| - ./app-hooks/post-upgrade:/docker-entrypoint-hooks.d/post-upgrade | ||
| - ./app-hooks/before-starting:/docker-entrypoint-hooks.d/before-starting | ||
| restart: unless-stopped | ||
| environment: | ||
| - POSTGRES_DB=${POSTGRES_DB:-nextcloud} | ||
|
|
@@ -33,6 +44,8 @@ services: | |
| - MAIL_FROM_ADDRESS | ||
| - MAIL_DOMAIN | ||
| - TZ | ||
| depends_on: | ||
| - redis | ||
| networks: | ||
| - internal | ||
|
|
||
|
|
@@ -63,6 +76,8 @@ services: | |
| - TZ | ||
| volumes: | ||
| - ./volumes/nextcloud:/var/www/html | ||
| depends_on: | ||
| - redis | ||
| networks: | ||
| - internal | ||
| entrypoint: /cron.sh | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new values are only added to
.env.example, but theappservice environment lists in the compose files never passNEXTCLOUD_BACKUP_DIRorNEXTCLOUD_UPGRADE_MIN_FREE_MBthrough to the container. In deployments that edit.envto change the backup path or free-space threshold as documented, the pre-upgrade hook still falls back to/backupsand2048, so the safety check and backup location cannot actually be configured from the sample env file. Add these variables to the app environment in both compose files.Useful? React with 👍 / 👎.