Skip to content

Commit

Permalink
nc-backup: faster free space calculation. Minimize maintenance mode time
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed May 15, 2018
1 parent 2ab49f4 commit e36a214
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

[v0.55.2](https://github.com/nextcloud/nextcloudpi/commit/9109d3a) (2018-05-14) nc-datadir: fix php cli tmpdir
[v0.55.3](https://github.com/nextcloud/nextcloudpi/commit/1c093f2) (2018-05-15) nc-backup: faster free space calculation. Minimize maintenance mode time

[v0.55.1](https://github.com/nextcloud/nextcloudpi/commit/a0a1145) (2018-05-14) nc-backup: exclude ncp-update-nc backups
[v0.55.2](https://github.com/nextcloud/nextcloudpi/commit/2ab49f4) (2018-05-14) nc-datadir: fix php cli tmpdir

[v0.55.1 ](https://github.com/nextcloud/nextcloudpi/commit/a0a1145) (2018-05-14) nc-backup: exclude ncp-update-nc backups

[v0.55.0 ](https://github.com/nextcloud/nextcloudpi/commit/935cf30) (2018-05-11) added nc-update-nextcloud

Expand Down
24 changes: 9 additions & 15 deletions etc/ncp-config.d/nc-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ set -eE
DESTDIR="${1:-/media/USBdrive/ncp-backups}"
INCLUDEDATA="${2:-no}"
COMPRESS="${3:-no}"
BACKUPLIMIT="${4:-4}"
BACKUPLIMIT="${4:-0}"
DESTFILE="$DESTDIR"/nextcloud-bkp_$( date +"%Y%m%d_%s" ).tar
DBBACKUP=nextcloud-sqlbkp_$( date +"%Y%m%d" ).bak
BASEDIR=/var/www
OCC="sudo -u www-data php /var/www/nextcloud/occ"
DATADIR=$( cd "$BASEDIR"/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || {
DATADIR=$( $OCC config:system:get datadirectory ) || {
echo "Error reading data directory. Is NextCloud running and configured?";
exit 1;
}
cleanup(){ local RET=$?; echo "Cleanup..."; rm -f "${DBBACKUP}" ; exit $RET; }
fail() { local RET=$?; echo "Abort..." ; rm -f "${DBBACKUP}" "${DESTFILE}"; exit $RET; }
cleanup(){ local RET=$?; rm -f "${DBBACKUP}" ; $OCC maintenance:mode --off; exit $RET; }
fail() { local RET=$?; echo "Abort..." ; rm -f "${DBBACKUP}" "${DESTFILE}"; $OCC maintenance:mode --off; exit $RET; }
trap cleanup EXIT
trap fail INT TERM HUP ERR
echo "check free space..."
echo "check free space..." # allow at least ~500 MiB for backups without data
mkdir -p "$DESTDIR"
SIZE=$( du -s "$DATADIR" | awk '{ print $1 }' )
[[ "$INCLUDEDATA" == "yes" ]] && SIZE=$( du -s "$DATADIR" | awk '{ print $1 }' ) || SIZE=500000
FREE=$( df "$DESTDIR" | tail -1 | awk '{ print $4 }' )
[ $SIZE -ge $FREE ] && {
Expand All @@ -66,7 +66,8 @@ FREE=$( df "$DESTDIR" | tail -1 | awk '{ print $4 }' )
}
# database
cd "$BASEDIR" || exit 1
cd /var/www || exit 1
$OCC maintenance:mode --on
echo "backup database..."
mysqldump -u root --single-transaction nextcloud > "$DBBACKUP"
Expand Down Expand Up @@ -113,14 +114,7 @@ EOF

configure()
{
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

ncp-backup "$DESTDIR_" "$INCLUDEDATA_" "$COMPRESS_" "$BACKUPLIMIT_"
local RET=$?

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

return $RET
}

# License
Expand Down

0 comments on commit e36a214

Please sign in to comment.