Skip to content

Instantly share code, notes, and snippets.

@lucarin91
Created May 24, 2019 09:47
Show Gist options
  • Save lucarin91/975948e0a26ca84275a7d052c68f3c16 to your computer and use it in GitHub Desktop.
Save lucarin91/975948e0a26ca84275a7d052c68f3c16 to your computer and use it in GitHub Desktop.
Simple script for backup Nextcloud data.
#!/bin/sh
set -x
NC_PATH="/var/www/nextcloud"
DST_PATH="/tmp"
DATE=$(date +"%Y%m%d")
# start maintenance
sudo -u www-data php "$NC_PATH/occ" maintenance:mode --on
# backup folder
tar -czf "$DST_PATH/nextcloud-dirbkp_$DATE.tar.gz" -C "$(dirname $NC_PATH)" "$(basename $NC_PATH)"
# backup database
sudo mysqldump --single-transaction -u[user] -p[password] [database] > "$DST_PATH/nextcloud-sqlbkp_$DATE.bak"
# stop maintenance
sudo -u www-data php "$NC_PATH/occ" maintenance:mode --off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment