Merge branch 'master' of gaw:applications/borgbackup_on_android
This commit is contained in:
commit
d7cab13826
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
sync_file_range_test
|
||||
borg
|
||||
borg_test
|
||||
borg-env
|
19
README.md
19
README.md
@ -11,10 +11,14 @@ How to use:
|
||||
- run "apt update; apt install git"
|
||||
- run "git clone https://github.com/ravenschade/borgbackup_on_android.git"
|
||||
- run "cd borgbackup_on_android; bash build.sh"
|
||||
- (if virtualenv for python does not work properly you have to set selinux to permissive (do "/system/bin/setenforce 0" with root permissions))
|
||||
|
||||
Known issues:
|
||||
- borg starting at 1.1 requires the system call sync_file_range (see https://github.com/borgbackup/borg/pull/985 and https://github.com/borgbackup/borg/issues/1961). The linux subsystem in Windows 10 and some older Android versions (for example Lineage including 14.1) do not yet have this. Lineage 15.0 has this call and should work. I have added a test to the build script that checks if sync_file_range is available. If it is not, then I apply a patch (borg_sync_file_range.patch) that replaces this sync with convential file syncs.
|
||||
|
||||
Tested with:
|
||||
- termux 0.53
|
||||
- borg 1.0.12
|
||||
- termux 0.56
|
||||
- borg 1.0.12, 1.1.3
|
||||
|
||||
Tested and working so far is:
|
||||
- creation of repositories
|
||||
@ -22,11 +26,18 @@ Tested and working so far is:
|
||||
- backup up to remote repositories via ssh
|
||||
|
||||
Tested and working on devices:
|
||||
- Huawei Nexus6p with stock Android 7.1.2 (angler, aarch64)
|
||||
- Samsung Galaxy Note 2 with Lineage 14.1 (n7100, armv7l)
|
||||
- Huawei Nexus6p with stock Android 8.1.0 (angler, aarch64)
|
||||
- Samsung Galaxy Note 2 with Lineage 14.1 (n7100, armv7l, Android 7.1.1)
|
||||
|
||||
Feedback on tests with other devices and android versions is very welcome.
|
||||
|
||||
Warning messages like
|
||||
````
|
||||
WARNING: linker: /data/data/com.termux/files/usr/lib/libacl.so.1.1.0: unused DT entry: type 0xf arg 0x449
|
||||
````
|
||||
are due to the Android linker. More details can be found at https://stackoverflow.com/questions/33206409/unused-dt-entry-type-0x1d-arg.
|
||||
|
||||
|
||||
So all in all my Android backup setup looks like:
|
||||
- borg, termux and tasker
|
||||
- termux: Task (https://f-droid.org/packages/com.termux.tasker/) for tasker integration
|
||||
|
23
borg.patch
23
borg.patch
@ -1,23 +0,0 @@
|
||||
diff --git setup.py setup.py
|
||||
index 33116acd..40db200f 100644
|
||||
--- setup.py
|
||||
+++ setup.py
|
||||
@@ -115,7 +115,7 @@ def detect_lz4(prefixes):
|
||||
include_dirs = []
|
||||
library_dirs = []
|
||||
|
||||
-possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl', '/usr/local/borg', '/opt/local']
|
||||
+possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl', '/usr/local/borg', '/opt/local', '/data/data/com.termux/files/usr/']
|
||||
if os.environ.get('BORG_OPENSSL_PREFIX'):
|
||||
possible_openssl_prefixes.insert(0, os.environ.get('BORG_OPENSSL_PREFIX'))
|
||||
ssl_prefix = detect_openssl(possible_openssl_prefixes)
|
||||
@@ -125,7 +125,7 @@ def detect_lz4(prefixes):
|
||||
library_dirs.append(os.path.join(ssl_prefix, 'lib'))
|
||||
|
||||
|
||||
-possible_lz4_prefixes = ['/usr', '/usr/local', '/usr/local/opt/lz4', '/usr/local/lz4', '/usr/local/borg', '/opt/local']
|
||||
+possible_lz4_prefixes = ['/usr', '/usr/local', '/usr/local/opt/lz4', '/usr/local/lz4', '/usr/local/borg', '/opt/local', '/data/data/com.termux/files/usr/']
|
||||
if os.environ.get('BORG_LZ4_PREFIX'):
|
||||
possible_lz4_prefixes.insert(0, os.environ.get('BORG_LZ4_PREFIX'))
|
||||
lz4_prefix = detect_lz4(possible_lz4_prefixes)
|
||||
|
9
borg.sh
Normal file
9
borg.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
t=`date +%d_%m_%Y`
|
||||
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
|
||||
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
|
||||
host=angler
|
||||
dirs="/ /system /vendor /cache /persist /firmware /storage /data"
|
||||
export BORG_RSH=borg_ssh_wrapper
|
||||
source /data/data/com.termux/files/home/borgbackup_on_android/borg-env/bin/activate
|
||||
borg create -C lz4 -p -v --stats --one-file-system backup:/backup/borg/$host::$t $dirs # 2> ~/borg_backup_${t}.err
|
16
borg_sync_file_range.patch
Normal file
16
borg_sync_file_range.patch
Normal file
@ -0,0 +1,16 @@
|
||||
diff --git a/src/borg/platform/linux.pyx b/src/borg/platform/linux.pyx
|
||||
index 25f71fa1..42ffa85f 100644
|
||||
--- a/src/borg/platform/linux.pyx
|
||||
+++ b/src/borg/platform/linux.pyx
|
||||
@@ -225,8 +225,9 @@ def acl_set(path, item, numeric_owner=False):
|
||||
cdef _sync_file_range(fd, offset, length, flags):
|
||||
assert offset & PAGE_MASK == 0, "offset %d not page-aligned" % offset
|
||||
assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
|
||||
- if sync_file_range(fd, offset, length, flags) != 0:
|
||||
- raise OSError(errno.errno, os.strerror(errno.errno))
|
||||
+ os.fdatasync(fd)
|
||||
+ #if sync_file_range(fd, offset, length, flags) != 0:
|
||||
+ # raise OSError(errno.errno, os.strerror(errno.errno))
|
||||
safe_fadvise(fd, offset, length, 'DONTNEED')
|
||||
|
||||
cdef unsigned PAGE_MASK = sysconf(_SC_PAGESIZE) - 1
|
32
build.sh
32
build.sh
@ -1,20 +1,29 @@
|
||||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
set -x
|
||||
set -xx
|
||||
apt update
|
||||
apt -y install make clang openssl-dev perl tsu wget git python python-dev gnupg dirmngr curl autoconf automake sed gettext gzip pkg-config
|
||||
|
||||
apt -y install make clang openssl-dev perl tsu wget git python python-dev gnupg dirmngr curl autoconf automake sed gettext gzip pkg-config libcrypt-dev
|
||||
|
||||
pip install virtualenv
|
||||
virtualenv --python=python3 borg-env
|
||||
source borg-env/bin/activate
|
||||
|
||||
git clone https://github.com/borgbackup/borg.git
|
||||
test -d borg || git clone https://github.com/borgbackup/borg.git
|
||||
cd borg
|
||||
git branch 1.0-maint remotes/origin/1.0-maint
|
||||
git checkout 1.0-maint
|
||||
git checkout 1.1.6
|
||||
|
||||
pip install Cython
|
||||
pip install -r requirements.d/development.txt
|
||||
|
||||
#find if sync_file_range is available
|
||||
s=`bash ../sync_file_range_test/test.sh`
|
||||
if [ "$s" = "1" ];
|
||||
then
|
||||
echo "patching borg to not use sync_file_range...."
|
||||
git apply ../borg_sync_file_range.patch
|
||||
else
|
||||
echo "no need to patch borg"
|
||||
fi
|
||||
|
||||
#download and build lz4
|
||||
wget https://github.com/lz4/lz4/archive/v1.7.5.tar.gz -O lz4.tar.gz
|
||||
tar -xf lz4.tar.gz
|
||||
@ -37,7 +46,7 @@ sed -i "s/\/bin\/sh/\/data\/data\/com.termux\/files\/usr\/bin\/sh/" include/inst
|
||||
sed -i "s/TMPDIR=\/tmp/TMPDIR=tmp/g" config.guess
|
||||
mkdir tmp
|
||||
|
||||
./configure CC=clang LDFLAGS=-lintl --prefix=/data/data/com.termux/files/usr/
|
||||
./configure CC=clang --prefix=/data/data/com.termux/files/usr/
|
||||
|
||||
#fix for ./include/attr/xattr.h:37:58: error: expected function body after function declarator
|
||||
# const void *__value, size_t __size, int __flags) __THROW;
|
||||
@ -61,13 +70,14 @@ sed -i "s/\/bin\/sh/\/data\/data\/com.termux\/files\/usr\/bin\/sh/" include/inst
|
||||
sed -i "s/TMPDIR=\/tmp/TMPDIR=tmp/g" config.guess
|
||||
mkdir tmp
|
||||
|
||||
./configure --prefix=/data/data/com.termux/files/usr/ CC=clang LDFLAGS=-lintl
|
||||
./configure --prefix=/data/data/com.termux/files/usr/ CC=clang
|
||||
make
|
||||
make install install-lib install-dev
|
||||
cd ..
|
||||
|
||||
#patching paths in setup.py
|
||||
patch -p0 < ../borg.patch
|
||||
#patching paths
|
||||
export BORG_OPENSSL_PREFIX="/data/data/com.termux/files/usr/"
|
||||
export BORG_LZ4_PREFIX="/data/data/com.termux/files/usr/"
|
||||
|
||||
pip install -e .
|
||||
|
||||
@ -79,7 +89,7 @@ cp borg_ssh_wrapper /data/data/com.termux/files/usr/bin/borg_ssh_wrapper
|
||||
chmod +x /data/data/com.termux/files/usr/bin/borg_ssh_wrapper
|
||||
|
||||
#test by creating a backup of the borg directory
|
||||
borg init borg_test
|
||||
borg init -e none borg_test
|
||||
borg create borg_test::1 borg
|
||||
borg list borg_test
|
||||
borg info borg_test::1
|
||||
|
6
sync_file_range_test/setup.py
Normal file
6
sync_file_range_test/setup.py
Normal file
@ -0,0 +1,6 @@
|
||||
# setup.py - unnecessary if not redistributing the code, see below
|
||||
from setuptools import setup
|
||||
from Cython.Build import cythonize
|
||||
|
||||
setup(name = 'Hello world app',
|
||||
ext_modules = cythonize("*.pyx"))
|
6
sync_file_range_test/sync_file_range_test.py
Normal file
6
sync_file_range_test/sync_file_range_test.py
Normal file
@ -0,0 +1,6 @@
|
||||
try:
|
||||
import sync_file_range_test
|
||||
except ImportError:
|
||||
raise ImportError('sync_file_range not existent')
|
||||
|
||||
sync_file_range_test.sync_file_range_test(0)
|
11
sync_file_range_test/sync_file_range_test.pyx
Normal file
11
sync_file_range_test/sync_file_range_test.pyx
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
cdef extern from "fcntl.h":
|
||||
int sync_file_range(int fd, int offset, int nbytes, unsigned int flags)
|
||||
|
||||
def sync_file_range_test(int x):
|
||||
print("sync_file_range exists\n")
|
||||
if x==-1:
|
||||
sync_file_range(1,1,1,1)
|
||||
|
||||
|
||||
|
5
sync_file_range_test/test.sh
Normal file
5
sync_file_range_test/test.sh
Normal file
@ -0,0 +1,5 @@
|
||||
cd ../sync_file_range_test/
|
||||
python setup.py build_ext --inplace > setup.log 2> setup.err
|
||||
python sync_file_range_test.py > test.log 2> test.err
|
||||
grep "sync_file_range not existent" test.err | tail -n 1 | wc -l
|
||||
|
Loading…
Reference in New Issue
Block a user