Skip to content

Commit 31f582b

Browse files
committed
add nc-restore-snapshot
1 parent 41a48c9 commit 31f582b

4 files changed

Lines changed: 86 additions & 6 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
#!/bin/bash
4+
# Nextcloud restore backup
5+
#
6+
# Copyleft 2019 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
7+
# GPL licensed (see end of file) * Use at your own risk!
8+
#
9+
# More at nextcloudpi.com
10+
#
11+
12+
install() { :; }
13+
14+
configure()
15+
{
16+
[[ -d "$SNAPSHOT" ]] || { echo "$SNAPSHOT doesn't exist"; return 1; }
17+
18+
local datadir mountpoint
19+
datadir=$( ncc config:system:get datadirectory ) || {
20+
echo -e "Error reading data directory. Is NextCloud running?";
21+
return 1;
22+
}
23+
24+
# file system check
25+
mountpoint="$( stat -c "%m" "$datadir" )" || return 1
26+
[[ "$( stat -fc%T "$mountpoint" )" != "btrfs" ]] && {
27+
echo "$datadir is not in a BTRFS filesystem"
28+
return 1
29+
}
30+
31+
# file system check
32+
btrfs subvolume show "$SNAPSHOT" &>/dev/null || {
33+
echo "$SNAPSHOT is not a BTRFS snapshot"
34+
return 1
35+
}
36+
37+
btrfs-snp $mountpoint autobackup 0 0 ../ncp-snapshots || return 1
38+
39+
ncc maintenance:mode --on
40+
btrfs subvolume delete "$datadir" || return 1
41+
btrfs subvolume snapshot "$SNAPSHOT" "$datadir"
42+
ncc maintenance:mode --off
43+
ncp-scan
44+
45+
echo "snapshot $SNAPSHOT restored"
46+
}
47+
48+
# License
49+
#
50+
# This script is free software; you can redistribute it and/or modify it
51+
# under the terms of the GNU General Public License as published by
52+
# the Free Software Foundation; either version 2 of the License, or
53+
# (at your option) any later version.
54+
#
55+
# This script is distributed in the hope that it will be useful,
56+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
57+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58+
# GNU General Public License for more details.
59+
#
60+
# You should have received a copy of the GNU General Public License
61+
# along with this script; if not, write to the
62+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
63+
# Boston, MA 02111-1307 USA
64+

bin/ncp/BACKUPS/nc-snapshot.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#
1010

1111

12-
BASEDIR=/var/www
13-
1412
install()
1513
{
1614
wget https://raw.githubusercontent.com/nachoparker/btrfs-snp/master/btrfs-snp -O /usr/local/bin/btrfs-snp
@@ -19,11 +17,11 @@ install()
1917

2018
configure()
2119
{
22-
sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on
20+
ncc maintenance:mode --on
2321

2422
local DATADIR MOUNTPOINT
25-
DATADIR=$( sudo -u www-data php /var/www/nextcloud/occ config:system:get datadirectory ) || {
26-
echo -e "Error reading data directory. Is NextCloud running and configured?";
23+
DATADIR=$( ncc config:system:get datadirectory ) || {
24+
echo -e "Error reading data directory. Is NextCloud running?";
2725
return 1;
2826
}
2927

@@ -36,7 +34,7 @@ configure()
3634

3735
btrfs-snp $MOUNTPOINT manual $LIMIT 0 ../ncp-snapshots
3836

39-
sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --off
37+
ncc maintenance:mode --off
4038
}
4139

4240
# License

bin/ncp/CONFIG/nc-datadir.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ configure()
9191
sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php/${PHPVER}/mods-available/opcache.ini
9292

9393
# update fail2ban logpath
94+
[[ -f /etc/fail2ban/jail.local ]] && \
9495
sed -i "s|logpath =.*nextcloud.log|logpath = $DATADIR/nextcloud.log|" /etc/fail2ban/jail.local
9596

9697
# datadir
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "nc-restore-snapshot",
3+
"name": "Nc-restore-snapshot",
4+
"title": "nc-restore-snapshot",
5+
"description": "Restore data from a BTRFS snapshot",
6+
"info": "A snapshot of the current data will be taken",
7+
"infotitle": "Restore NextCloud data snapshot",
8+
"params": [
9+
{
10+
"id": "SNAPSHOT",
11+
"name": "Snapshot Path",
12+
"value": "",
13+
"suggest": "/media/USBdrive/ncp-snapshots/daily_XXXX-XX-XX_XXXXXX",
14+
"type": "directory"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)