Skip to content

Commit 5a80299

Browse files
author
nacho
committed
nc-snapshot: use btrfs-snp
1 parent 15587e8 commit 5a80299

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

changelog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

2-
[v0.44.0](https://github.com/nextcloud/nextcloudpi/commit/186639f) (2017-12-28) added nc-snapshot-auto
2+
[v0.44.1](https://github.com/nextcloud/nextcloudpi/commit/72699f5) (2017-12-28) nc-snapshot: use btrfs-snp
3+
4+
[v0.44.0](https://github.com/nextcloud/nextcloudpi/commit/15587e8) (2017-12-28) added nc-snapshot-auto
35

46
[v0.43.3 ](https://github.com/nextcloud/nextcloudpi/commit/f6ab161) (2017-12-26) nc-datadir: use clone on btrfs systems
57

6-
[v0.43.2](https://github.com/nextcloud/nextcloudpi/commit/ae8d30b) (2017-12-19) UFW: prettier output
8+
[v0.43.2 ](https://github.com/nextcloud/nextcloudpi/commit/ae8d30b) (2017-12-19) UFW: prettier output
79

810
[v0.43.1 ](https://github.com/nextcloud/nextcloudpi/commit/114ea18) (2017-12-19) ncp-config: validate input
911

etc/nextcloudpi-config.d/nc-snapshot.sh

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,34 @@ to the next are saved. This requires the datadir to be in a BTRFS filesystem"
2121

2222
BASEDIR=/var/www
2323

24+
install()
25+
{
26+
wget https://raw.githubusercontent.com/nachoparker/btrfs-snp/master/btrfs-snp -O /usr/local/bin/btrfs-snp
27+
chmod +x /usr/local/bin/btrfs-snp
28+
}
29+
2430
configure()
2531
{
26-
local DATADIR
27-
DATADIR=$( cd "$BASEDIR"/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || {
32+
sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on
33+
34+
local DATADIR MOUNTPOINT
35+
DATADIR=$( sudo -u www-data php /var/www/nextcloud/occ config:system:get datadirectory ) || {
2836
echo -e "Error reading data directory. Is NextCloud running and configured?";
2937
return 1;
3038
}
31-
local SNAPSHOT=${DATADIR}_$( date +"%F" )
3239

3340
# file system check
34-
[[ "$( stat -fc%T "$DATADIR" )" != "btrfs" ]] && {
35-
echo "The datadir is not in a BTRFS filesystem"
41+
MOUNTPOINT="$( stat -c "%m" "$DATADIR" )" || return 1
42+
[[ "$( stat -fc%T "$MOUNTPOINT" )" != "btrfs" ]] && {
43+
echo "$MOUNTPOINT is not in a BTRFS filesystem"
3644
return 1
3745
}
38-
local DESTDIR="$( dirname "$DATADIR" )"
39-
40-
# do it
41-
sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on
42-
43-
[[ -d "$SNAPSHOT" ]] && {
44-
btrfs subvolume delete "$SNAPSHOT" &>/dev/null
45-
rm -rf "$SNAPSHOT" &>/dev/null
46-
}
47-
btrfs subvolume snapshot -r "$DATADIR" "$SNAPSHOT" || return 1
4846

49-
# prune older backups
50-
[[ $LIMIT_ != 0 ]] && {
51-
52-
local SNAPS=( $( btrfs subvolume list -s --sort=gen "$DESTDIR" | awk '{ print $14 }' ) )
53-
cd "$DESTDIR" || return 1
54-
[[ ${#SNAPS[@]} -gt $LIMIT_ ]] && \
55-
echo "Pruning old snapshots..." && \
56-
for (( i=0; i < $(( ${#SNAPS[@]} - LIMIT_ )); i++ ));do
57-
btrfs subvolume delete "${SNAPS[$i]}"
58-
done
59-
}
47+
btrfs-snp $MOUNTPOINT manual $LIMIT_ 0 ../ncp-snapshots
6048

6149
sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --off
62-
echo -e "snapshot $SNAPSHOT generated"
6350
}
6451

65-
install() { :; }
66-
6752
# License
6853
#
6954
# This script is free software; you can redistribute it and/or modify it

0 commit comments

Comments
 (0)