[Android General] outsidetheboxx:
About this backup solution

We make use of restic here, a standalone command-line backup tool which generally works on all major platforms (Linux, BSD, Mac, Windows WSL, and Android)

restic is free Open Source software and backups are end-to-end encrypted per default

it allows you to store your encrypted backups both locally or on a remote server (in my guide below I will show you how to backup to sd card, own server, and Nextcloud, but there are even more storage types)

backups are de-duplicated, incremental and compressed, which saves you a lot of time, space, and data usage

as restic is a independent tool this backup solution does NOT depend on adb, adb backup, adb root, root debugging or custom shell scripts

it allows you to backup all the data on your device if you have root, so you don't have to deal with backups being incomplete as in the case of SeedVault when certain apps have set a "do not backup" flag

restoring data works in two ways: specifying a certain path on Android to restore to or you mount a backup snapshot on your desktop file system and just copy files out of there (there is also a open source restic file explorer software to simplify this, see Restic Browser in honorable mentions below)

Downsides of this backup solution

Without root you are only able to backup internal storage (of personal and work profiles) and sd card

We have to utilize the command line (Termux), if you are fine with that, this guide should be pretty straight foward for you :)

restic consumes more RAM the bigger your backup repository gets (I guess we are talking about TBs here, my Fairphone 4 has 8 GB RAM, and worked perfectly fine so far)

<Your feedback is needed here>

I successfully tested this method on a Fairphone 4 with /e/OS R (Android 11) and S (Android 12).

Please note that the app data directories given in the examples here could differ depending on your specific device. The given sd card and internal storage paths should match accross most devices, I hope.

For more details on the usage of restic please refer to the restic documentation. I won't go into topics like tags, backup rotation, key management, etc. here.

Honorable mentions

This guide uses restic natively via command line. If you prefer to use a GUI, there is a unofficial experimental Restic Backup Android App on F-Droid (I won't cover this app here as it is quite limited as of now and therefore doesn't offer the same capabilites on which we rely in this guide)

Restic Browser provides you with a GUI to browse and restore your restic backup repositories on your Windows/Linux/MacOS desktop machine

For those ppl who prefer a similar encrypted FLOSS backup solution: Instead of restic you can also use BorgBackup via Termux. It can be installed using the command: pkg install borgbackup

Prerequisites

Termux installed (install via F-Droid)

Grant Termux file access permissions in app settings (else you will run into permission denied errors when running restic)

For full backups: root (e.g. Magisk), Termux needs to be able to run as Superuser when running restic with sudo

1 Initial Setup: Install restic via Termux

Update packages

apt update
apt upgrade

-> If there are any prompts just hit ENTER all the time

Update all termux packages

pkg upgrade

Install sudo (ROOT ONLY)

pkg install tsu

Install restic

pkg install restic

Check if restic was installed successfully

restic version

2 Backing up your data

2.1 OPTION 1: Backup to sd card

❗ Replace "/storage/XXXX-XXXX/" with your sd card path ❗

Create backups folder on sd card

mkdir /storage/XXXX-XXXX/backups/

Initialize restic backup repository

❗ This step is only needed once at first setup ❗

restic init -r /storage/XXXX-XXXX/backups/

Backup internal storage (without root) (default/personal profile)

restic -r /storage/XXXX-XXXX/backups backup /storage/emulated/0/ --verbose

Backup app data (with root) (default/personal profile)

sudo restic -r /storage/XXXX-XXXX/backups backup /data/data/ /data/user/0/ /data/user_de/0/ --verbose

Show all backups

restic -r /storage/XXXX-XXXX/backups snapshots

Restore backup (latest backup)

restic -r /storage/XXXX-XXXX/backups restore --target /storage/emulated/0/my-restore-directory latest

Browse your backups / Mount backup repository to file system (for example on your desktop machine)

❗ In order to use this restic needs also to be installed on your desktop machine ❗

mkdir /mnt/restic
restic -r /your/sdcard/path/backups mount /mnt/restic

If you prefer a GUI for browsing your backups on your desktop machine: Use Restic Browser.

2.2 OPTION 2: Backup to (your) Nextcloud via WebDAV

❗ restic doesn't support backing up to Nextcloud instances (WebDAV) out of the box, it needs rclone for that ❗

Update packages

apt update
apt upgrade

-> If there are any prompts just hit ENTER all the time

Update all termux packages

pkg upgrade

Install rclone

pkg install rclone

Configure rclone

rclone config

Create new remote

-> n

Specify name of your backup destination

-> NextcloudWebDAV (or whatever name you like)

Specify type of your backup server

-> Choose number corresponding to WebDAV

Specify backup-server URL

-> Log into Nextcloud, navigate to Files -> open menu -> Files settings -> copy WebDAV path from there (alternatively, use the URL below and replace example.com with your Nextcloud URL and USERNAME with your username)

-> https://example.com/remote.php/dav/files/USERNAME/

Choose WebDAV Type

-> Choose number corresponding to Nextcloud

Specify Nextcloud username

-> Enter your Nextcloud USERNAME

Specify Nextcloud password

❗ For security reasons it is recommended to use a dedicated App password ❗

-> Log into Nextcloud, navigate to Settings -> Security -> scroll down to Devices & sessions -> Fill in a app name of your liking, e.g. "restic-Android" -> Create new app password -> copy to clipboard

-> y

-> Enter your Nextcloud PASSWORD

Skip Bearer token process

-> ENTER (to skip)

Save configuration

-> n

Confirm your configuration

-> y

Your added cloud server will be listed as current remote

Finally, you can quit rclone

-> q

Test WebDAV connection to cloud via rclone

❗ Don't miss the colon ":" after the name) ❗

rclone lsd NextcloudWebDAV:

-> Should display files and folders you have inside your Nextcloud:

Initialize restic backup repository

❗ This step is only needed once at first setup ❗

restic -r rclone:NextcloudWebDAV:/backups init

Backup internal storage (without root) (default/personal profile)

restic -r rclone:NextcloudWebDAV:/backups backup /storage/emulated/0/ --verbose

Backup app data (with root) (default/personal profile)

sudo restic -r rclone:NextcloudWebDAV:/backups backup /data/data/ /data/user/0/ /data/user_de/0/ --verbose

Show all backups

restic -r rclone:NextcloudWebDAV:/backups snapshots

Restore backup (latest backup)

restic -r rclone:NextcloudWebDAV:/backups restore --target /storage/emulated/0/my-restore-directory latest

Browse your backups / Mount backup repository to file system (for example on your desktop machine)

❗ In order to use this restic needs also to be installed on your desktop machine ❗

mkdir /mnt/restic
restic -r rclone:NextcloudWebDAV:/backups mount /mnt/restic

If you prefer a GUI for browsing your backups on your desktop machine: Use Restic Browser.

2.3 OPTION 3: Backup to own server via SFTP/SSH

❗ needs restic and OpenSSH to be installed on both sides (Android & server) ❗

Install OpenSSH

pkg install openssh

Create a dedicated user for restic on your server

❗ Replace HOST and USER below with the ones of your server ❗

Initialize restic backup repository

❗ This step is only needed once at first setup ❗

restic -r sftp:USER@HOST:backups init

On first connection you will be prompted once to verify the key fingerprint of your server

-> yes

Backup internal storage (without root) (default/personal profile)

restic -r sftp:USER@HOST:backups backup /storage/emulated/0/ --verbose

Backup app data (with root) (default/personal profile)

sudo restic -r sftp:USER@HOST:backups backup /data/data/ /data/user/0/ /data/user_de/0/ --verbose

Show all backups

restic -r sftp:USER@HOST:backups snapshots

Restore backup (latest backup)

restic -r sftp:USER@HOST:backups restore --target /storage/emulated/0/my-restore-directory latest

Browse your backups / Mount backup repository to file system (for example on your desktop machine)

❗ In order to use this restic needs also to be installed on your desktop machine ❗

mkdir /mnt/restic
restic -r sftp:USER@HOST:backups mount /mnt/restic

If you prefer a GUI for browsing your backups on your desktop machine: Use Restic Browser.

3 Advanced usage

Backup work profile (without root)

Install Termux in work profile or clone to work profile using Shelter/Island/Insular

Run following commands from Termux in work profile:

Backup internal storage of work profile to sd card

restic -r /storage/XXXX-XXXX/backups backup /storage/emulated/10/ --verbose

Backup internal storage of work profile to Nextcloud

❗ To make this work first repeat rclone configuration steps from guide above with Termux in work profile ❗

restic -r rclone:NextcloudWebDAV:/backups backup /storage/emulated/10/ --verbose

Backup internal storage of work profile to server via SFTP/SSH

restic -r sftp:USER@HOST:backups backup /storage/emulated/10/ --verbose

Backup work profile (with root)

No need to install Termux to work profile, just use sudo and specify work profile path (/data/media/10/)

Backup internal storage of work profile to sd card (root)

sudo restic -r /storage/XXXX-XXXX/backups backup /data/media/10/ --verbose

Backup internal storage of work profile to Nextcloud (root)

❗ to make this work first repeat rclone configuration steps from guide above using: sudo rclone config ❗

sudo restic -r rclone:NextcloudWebDAV:/backups backup /data/media/10/ --verbose

Backup internal storage of work profile to SSH server (root)

sudo restic -r sftp:USER@HOST:backups backup /data/media/10/ --verbose

This guide was originally posted by me on the /e/ Community forums on Sep 23, 2023 and is just slightly adapted to a more general use here.