Skip to content

Commit

Permalink
nc-snapshot-auto: read datadir location during execution
Browse files Browse the repository at this point in the history
Signed-off-by: nachoparker <nacho@ownyourbits.com>
  • Loading branch information
nachoparker committed Mar 16, 2020
1 parent f71c8c8 commit c09dfd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
39 changes: 19 additions & 20 deletions bin/ncp/BACKUPS/nc-snapshot-auto.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#
# NextCloudPi scheduled datadir BTRFS snapshots
# NextCloudPi scheduled datadir BTRFS snapshots
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
Expand All @@ -17,32 +17,31 @@ install()
}

configure()
{
[[ $ACTIVE != "yes" ]] && {
{
[[ "$ACTIVE" != "yes" ]] && {
rm -f /etc/cron.hourly/btrfs-snp
echo "automatic snapshots disabled"
return 0
}

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;
}

# file system check
MOUNTPOINT="$( stat -c "%m" "$DATADIR" )" || return 1
[[ "$( stat -fc%T "$MOUNTPOINT" )" != "btrfs" ]] && {
echo "$MOUNTPOINT is not in a BTRFS filesystem"
return 1
}

cat > /etc/cron.hourly/btrfs-snp <<EOF
#!/bin/bash
/usr/local/bin/btrfs-snp $MOUNTPOINT hourly 24 3600 ../ncp-snapshots
/usr/local/bin/btrfs-snp $MOUNTPOINT daily 7 86400 ../ncp-snapshots
/usr/local/bin/btrfs-snp $MOUNTPOINT weekly 4 604800 ../ncp-snapshots
/usr/local/bin/btrfs-snp $MOUNTPOINT monthly 12 2592000 ../ncp-snapshots
DATADIR=\$(ncc config:system:get datadirectory) || {
echo -e "Error reading data directory. Is NextCloud running and configured?";
exit 1;
}
# file system check
MOUNTPOINT="\$(stat -c "%m" "\$DATADIR")" || return 1
[[ "\$( stat -fc%T "\$MOUNTPOINT" )" != "btrfs" ]] && {
echo "\$MOUNTPOINT is not in a BTRFS filesystem"
exit 1
}
/usr/local/bin/btrfs-snp \$MOUNTPOINT hourly 24 3600 ../ncp-snapshots
/usr/local/bin/btrfs-snp \$MOUNTPOINT daily 7 86400 ../ncp-snapshots
/usr/local/bin/btrfs-snp \$MOUNTPOINT weekly 4 604800 ../ncp-snapshots
/usr/local/bin/btrfs-snp \$MOUNTPOINT monthly 12 2592000 ../ncp-snapshots
EOF
chmod 755 /etc/cron.hourly/btrfs-snp
echo "automatic snapshots enabled"
Expand Down
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

[v1.22.1](https://github.com/nextcloud/nextcloudpi/commit/e68d616) (2020-03-03) samba: option to apply only to a NC group (#1048)
[v1.22.3](https://github.com/nextcloud/nextcloudpi/commit/0e81bc1) (2020-03-02) nc-snapshot-auto: read datadir location during execution

[v1.22.2 ](https://github.com/nextcloud/nextcloudpi/commit/75b1a06) (2020-03-02) nc-maintenance: add is_active

[v1.22.1](https://github.com/nextcloud/nextcloudpi/commit/49de98b) (2020-03-03) samba: option to apply only to a NC group (#1048)

[v1.22.0 ](https://github.com/nextcloud/nextcloudpi/commit/9304c86) (2020-03-03) Add nc-trusted-proxies (#1094)

Expand Down

0 comments on commit c09dfd9

Please sign in to comment.