Skip to content

Commit

Permalink
nc-snapshot: use btrfs-snp
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Dec 28, 2017
1 parent 15587e8 commit 5a80299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
6 changes: 4 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
43 changes: 14 additions & 29 deletions etc/nextcloudpi-config.d/nc-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a80299

Please sign in to comment.