Skip to content

Commit b663e32

Browse files
author
nacho
committed
added nc-snapshot-sync
1 parent 5e9cb51 commit b663e32

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

changelog.md

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

2-
[v0.47.3](https://github.com/nextcloud/nextcloudpi/commit/4156bb7) (2018-03-16) fix for nc-automount-links
2+
[v0.50.0](https://github.com/nextcloud/nextcloudpi/commit/1937d28) (2018-03-12) added nc-snapshot-sync
33

4-
[v0.47.2](https://github.com/nextcloud/nextcloudpi/commit/66cb00a) (2018-03-15) improve dependency of database with automount
4+
[v0.47.4 ](https://github.com/nextcloud/nextcloudpi/commit/5e9cb51) (2018-03-14) Add template generation functionality to L10N.php (activate by setting constant GENERATE_TEMPLATES to true).
5+
6+
[v0.47.3](https://github.com/nextcloud/nextcloudpi/commit/fd9fc8c) (2018-03-16) fix for nc-automount-links
7+
8+
[v0.47.2 ](https://github.com/nextcloud/nextcloudpi/commit/66cb00a) (2018-03-15) improve dependency of database with automount
59

610
[v0.47.1 ](https://github.com/nextcloud/nextcloudpi/commit/9f6c479) (2018-03-10) update: make sure redis log exists
711

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
# Sync Nextcloud BTRFS snapshots
4+
#
5+
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
6+
# GPL licensed (see end of file) * Use at your own risk!
7+
#
8+
# Usage:
9+
#
10+
# ./installer.sh nc-snapshot-sync.sh <IP> (<img>)
11+
#
12+
# See installer.sh instructions for details
13+
#
14+
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
15+
#
16+
17+
ACTIVE_=no
18+
SNAPDIR_=/media/USBdrive/ncp-snapshots
19+
DESTINATION_=/media/myBackupDrive/ncp-snapshots
20+
COMPRESSION_=no
21+
SYNCDAYS_=1
22+
DESCRIPTION="Sync BTRFS snapshots to USBdrive or remote machine"
23+
24+
INFO="Use format user@ip:/path/to/snapshots for remote sync
25+
'user' needs permissions for the 'btrfs' command at 'ip'
26+
'user' needs SSH autologin from the NCP 'root' user at 'ip'
27+
Only use compression for internet transfer, because it uses many resources"
28+
29+
install()
30+
{
31+
apt-get update
32+
apt-get install -y --no-install-recommends pv
33+
wget https://raw.githubusercontent.com/nachoparker/btrfs-sync/master/btrfs-sync -O /usr/local/bin/btrfs-sync
34+
chmod +x /usr/local/bin/btrfs-sync
35+
ssh-keygen -N "" -f /root/.ssh/id_rsa
36+
}
37+
38+
configure()
39+
{
40+
[[ $ACTIVE_ != "yes" ]] && {
41+
rm /etc/cron.d/ncp-snapsync-auto
42+
service cron restart
43+
echo "snapshot sync disabled"
44+
return 0
45+
}
46+
47+
# checks
48+
[[ -d "$SNAPDIR_" ]] || { echo "$SNAPDIR_ does not exist"; return 1; }
49+
50+
[[ "$DESTINATION_" =~ : ]] && {
51+
local NET="$( sed 's|:.*||' <<<"$DESTINATION_" )"
52+
local DST="$( sed 's|.*:||' <<<"$DESTINATION_" )"
53+
local SSH=( ssh -o "BatchMode=yes" "$NET" )
54+
${SSH[@]} : || { echo "SSH non-interactive not properly configured"; return 1; }
55+
} || DST="$DESTINATION_"
56+
[[ "$( ${SSH[@]} stat -fc%T "$DST" )" != "btrfs" ]] && {
57+
echo "$DESTINATION_ is not in a BTRFS filesystem"
58+
return 1
59+
}
60+
61+
[[ "$COMPRESSION_" == "yes" ]] && ZIP="-z"
62+
63+
echo "30 4 */${SYNCDAYS_} * * root /usr/local/bin/btrfs-sync -qd $ZIP \"$SNAPDIR_\" \"$DESTINATION_\"" > /etc/cron.d/ncp-snapsync-auto
64+
service cron restart
65+
echo "snapshot sync enabled"
66+
}
67+
68+
# License
69+
#
70+
# This script is free software; you can redistribute it and/or modify it
71+
# under the terms of the GNU General Public License as published by
72+
# the Free Software Foundation; either version 2 of the License, or
73+
# (at your option) any later version.
74+
#
75+
# This script is distributed in the hope that it will be useful,
76+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
77+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78+
# GNU General Public License for more details.
79+
#
80+
# You should have received a copy of the GNU General Public License
81+
# along with this script; if not, write to the
82+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
83+
# Boston, MA 02111-1307 USA
84+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
23
# Nextcloud BTRFS snapshots
34
#
45
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>

ncp-web/ncp-launcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
{
119119
$value = "[". join(",", $value) ."]";
120120
}
121-
preg_match( '/^[\[\]\w.,@_\/-]+$/' , $value , $matches )
121+
preg_match( '/^[\[\]\w.,@_\/-:]+$/' , $value , $matches )
122122
or exit( '{ "output": "Invalid input" , "token": "' . getCSRFToken() . '" }' );
123123
$code = preg_replace( '/\n' . $name . '_=.*' . PHP_EOL . '/' ,
124124
PHP_EOL . $name . '_=' . $value . PHP_EOL ,

0 commit comments

Comments
 (0)