Skip to content

Instantly share code, notes, and snippets.

@R0Wi
Created July 7, 2024 11:02
Show Gist options
  • Save R0Wi/9b95714cbc2c9fd5d835dcfbf9c9a8ec to your computer and use it in GitHub Desktop.
Save R0Wi/9b95714cbc2c9fd5d835dcfbf9c9a8ec to your computer and use it in GitHub Desktop.
Nextcloud update script with database backup
#!/bin/bash
#######################################
# Nextcloud update script
# (c) R0Wi 2024
#######################################
set -Eeou pipefail
SCRIPT_DIR="$(dirname $(realpath $0))"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
# Adjust the following variables to your need
NC_DIR="/var/www/nextcloud"
NC_USER="www-data"
DB_BACKUP_TMP="${SCRIPT_DIR}/db_backup"
DB_NAMEUSER="nextcloud"
DB="nextcloud"
DB_PW="someDbPass"
# Set maintenance
pushd "$NC_DIR"
echo "Setting NC maintenance mode to on"
sudo -u $NC_USER php occ maintenance:mode --on
# SQL backups
DB_BACKUP_TARGET="${DB_BACKUP_TMP}/${DB_NAMEUSER}_${TIMESTAMP}.sql.gz"
echo "Writing SQL dump to ${DB_BACKUP_TARGET}"
mysqldump -h localhost -u "$DB_NAMEUSER" -p"$DB_PW" "$DB" | gzip -9 -c > "${DB_BACKUP_TARGET}"
# Run the update
echo "Starting updater"
sudo -u $NC_USER php updater/updater.phar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment