From 5a80299446d4ed9b5a6d19ab972832a10c960a89 Mon Sep 17 00:00:00 2001 From: nacho Date: Thu, 28 Dec 2017 12:33:43 +0100 Subject: [PATCH] nc-snapshot: use btrfs-snp --- changelog.md | 6 ++-- etc/nextcloudpi-config.d/nc-snapshot.sh | 43 ++++++++----------------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/changelog.md b/changelog.md index 84dfb7110..99fb0a3c5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,11 @@ -[v0.44.0](https://github.com/nextcloud/nextcloudpi/commit/186639f) (2017-12-28) added nc-snapshot-auto +[v0.44.1](https://github.com/nextcloud/nextcloudpi/commit/72699f5) (2017-12-28) nc-snapshot: use btrfs-snp + +[v0.44.0](https://github.com/nextcloud/nextcloudpi/commit/15587e8) (2017-12-28) added nc-snapshot-auto [v0.43.3 ](https://github.com/nextcloud/nextcloudpi/commit/f6ab161) (2017-12-26) nc-datadir: use clone on btrfs systems -[v0.43.2](https://github.com/nextcloud/nextcloudpi/commit/ae8d30b) (2017-12-19) UFW: prettier output +[v0.43.2 ](https://github.com/nextcloud/nextcloudpi/commit/ae8d30b) (2017-12-19) UFW: prettier output [v0.43.1 ](https://github.com/nextcloud/nextcloudpi/commit/114ea18) (2017-12-19) ncp-config: validate input diff --git a/etc/nextcloudpi-config.d/nc-snapshot.sh b/etc/nextcloudpi-config.d/nc-snapshot.sh index 5df87e18d..00a39ce3d 100644 --- a/etc/nextcloudpi-config.d/nc-snapshot.sh +++ b/etc/nextcloudpi-config.d/nc-snapshot.sh @@ -21,49 +21,34 @@ to the next are saved. This requires the datadir to be in a BTRFS filesystem" BASEDIR=/var/www +install() +{ + wget https://raw.githubusercontent.com/nachoparker/btrfs-snp/master/btrfs-snp -O /usr/local/bin/btrfs-snp + chmod +x /usr/local/bin/btrfs-snp +} + configure() { - local DATADIR - DATADIR=$( cd "$BASEDIR"/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || { + sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on + + local DATADIR MOUNTPOINT + DATADIR=$( sudo -u www-data php /var/www/nextcloud/occ config:system:get datadirectory ) || { echo -e "Error reading data directory. Is NextCloud running and configured?"; return 1; } - local SNAPSHOT=${DATADIR}_$( date +"%F" ) # file system check - [[ "$( stat -fc%T "$DATADIR" )" != "btrfs" ]] && { - echo "The datadir is not in a BTRFS filesystem" + MOUNTPOINT="$( stat -c "%m" "$DATADIR" )" || return 1 + [[ "$( stat -fc%T "$MOUNTPOINT" )" != "btrfs" ]] && { + echo "$MOUNTPOINT is not in a BTRFS filesystem" return 1 } - local DESTDIR="$( dirname "$DATADIR" )" - - # do it - sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on - - [[ -d "$SNAPSHOT" ]] && { - btrfs subvolume delete "$SNAPSHOT" &>/dev/null - rm -rf "$SNAPSHOT" &>/dev/null - } - btrfs subvolume snapshot -r "$DATADIR" "$SNAPSHOT" || return 1 - # prune older backups - [[ $LIMIT_ != 0 ]] && { - - local SNAPS=( $( btrfs subvolume list -s --sort=gen "$DESTDIR" | awk '{ print $14 }' ) ) - cd "$DESTDIR" || return 1 - [[ ${#SNAPS[@]} -gt $LIMIT_ ]] && \ - echo "Pruning old snapshots..." && \ - for (( i=0; i < $(( ${#SNAPS[@]} - LIMIT_ )); i++ ));do - btrfs subvolume delete "${SNAPS[$i]}" - done - } + btrfs-snp $MOUNTPOINT manual $LIMIT_ 0 ../ncp-snapshots sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --off - echo -e "snapshot $SNAPSHOT generated" } -install() { :; } - # License # # This script is free software; you can redistribute it and/or modify it