diff --git a/README.md b/README.md index 2ad0e3e..5f149ef 100644 --- a/README.md +++ b/README.md @@ -11,11 +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)) - + - (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.56 -- borg 1.1.3 +- borg 1.0.12, 1.1.3 Tested and working so far is: - creation of repositories diff --git a/borg_sync_file_range.patch b/borg_sync_file_range.patch new file mode 100644 index 0000000..9813709 --- /dev/null +++ b/borg_sync_file_range.patch @@ -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 diff --git a/build.sh b/build.sh index 5ebfe15..b7a1f27 100755 --- a/build.sh +++ b/build.sh @@ -14,6 +14,16 @@ git checkout 1.1-maint 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 diff --git a/sync_file_range_test/setup.py b/sync_file_range_test/setup.py new file mode 100644 index 0000000..2650992 --- /dev/null +++ b/sync_file_range_test/setup.py @@ -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")) diff --git a/sync_file_range_test/sync_file_range_test.py b/sync_file_range_test/sync_file_range_test.py new file mode 100644 index 0000000..30af0f2 --- /dev/null +++ b/sync_file_range_test/sync_file_range_test.py @@ -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) diff --git a/sync_file_range_test/sync_file_range_test.pyx b/sync_file_range_test/sync_file_range_test.pyx new file mode 100644 index 0000000..ff4bb9e --- /dev/null +++ b/sync_file_range_test/sync_file_range_test.pyx @@ -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) + + + diff --git a/sync_file_range_test/test.sh b/sync_file_range_test/test.sh new file mode 100644 index 0000000..d61e36d --- /dev/null +++ b/sync_file_range_test/test.sh @@ -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 +