UGMA

Un-Google My Android

An introduction to backing up your Android device to your own cloud, not to Google.

For better layout, you can download the LibreOffice version or the PDF version of this document.

NOTE: this is not (quite) a newbie guide.  You will need at least some basic experience with the Linux command-line.  However: there should be enough here that with a bit of Googling and some persistence, you should be able to get it all working.  Grab your nearest Linux guru and have them on standby, just in case.  ;-)

NOTE: this is a work in progress, and will probably be updated every day or two while I fix formatting etc.  If you’re willing to read through the list of commands to execute, you can probably make it work anyway.  If you have little or no Linux troubleshooting experience, come back in a day or two.

1Introduction

This guide will help you set up a fresh installation of LineageOS on a device and connect it to a new CentOS Linux instance hosted by Digital Ocean.  From what you learn doing this, and with some additional information in this guide and elsewhere, you should be able to adapt this configuration to suit your needs, your specific device, or your preferred Linux hosting environment.

1.1Goals

The goals of the setup are:

  1. 1.Back up your Android device (enable online backup and restore of a single Android device) 

  2. 2.Synchronise your Android device (enable synchronisation of your data & files between Android devices) 

  3. 3.Access your Android device's data online (enable online access to your data and files) 

Not all software can easily be backed up with this system, so you may have to experiment and adapt it to suit your needs depending on what apps you have running on your device.

1.2Requirements

1.3Assumptions

This documentation makes the following assumptions about your skills:

1.4Typographic conventions

Some things to note:

Format

Purpose

literal text

Denotes the name of a file, text you must place into a file, or a command you should type into a Linux console (depending on context).  In most cases, you could simply copy this and paste it into the console.

Placeholder (in prose); or
Placeholder (in literal text)

Denotes something that you should replace; typically the placeholder text describes what should go there.  Watch out when copy/pasting text with placeholders: be sure to replace them with something suitable!

 

1.5Relax!

Although this is a long document, most of the server-side setup can be done by copy-paste, as long as you use the same environment used in the documentation (a CentOS 7 VM hosted at Digital Ocean).

2What to back up

Here's a list of some of the things you might like backed up or synchronised from your Android device, and what this guide currently helps you achieve:

Category

Item

Status

Common user data

Calendars

Synchronised

Contacts

Synchronised

Phone call logs

Backed up to IMAP and a calendar

SMS messages

Backed up to IMAP

Photos/videos

Synchronised

Music

Not yet done...

Browser bookmarks

Not yet done...

Browser passwords

Not yet done...

General passwords

Not yet done...

Other

Not yet done...

Application-specific data

Application files (APKs)

Not yet done...

Application preferences

Not yet done...

Application data

Not yet done...

System data

System accounts

Not yet done...

System preferences

Not yet done...

 

 

3Recording important information

Here’s a table to print and fill in while going through this process.  Mostly, you’ll want to store passwords here.  Be sure to generate some secure ones!  If you want truly random ones, consider using GRC’s password generator.

Server information

IP address

 

Hostname

 

Root password

(n/a – use SSH-based password-less login)

Database management information

Database management password

 

Database configuration

Nextcloud database user name

nextcloud

Nextcloud database user password

 

Nextcloud database

nextcloud

Nextcloud administrator user

Nextcloud admin user name

admin

Nextcloud admin user password

 

Nextcloud user (ie: your normal Nextcloud account)

Nextcloud normal user name

 

Nextcloud normal user password

 

Mail account for SMS backups (ie: IMAP account)

SMS user name

 

SMS password

 

 

 

4Setting up the server

4.1Installing the operating system (CentOS 7.x)

Any hosting environment would suffice, be it physical or virtual.  If you want to set up a virtual environment, try Digital Ocean they have VMs for as little as USD5 per month.

Here’s a discount code to get you USD10 credit with Digital Ocean (enough for two months of free hosting): https://m.do.co/c/463c92da0f84.

Installing CentOS is out of the scope of this documentation, but with Digital Ocean it’s just a few clicks away.  Even better, you only pay for your hosting by the hour, which makes for great experimentation for just a few cents!  As long as you destroy any experimental VMs when you’re done with them, they’ll cost you next to nothing.

The rest of the commands in this section should be done at a root prompt on the virtual machine.

4.1.1Why CentOS?

This is almost entirely because I’m most familiar with CentOS; you could just as easily use Debian, Ubuntu, Fedora, Suse, or just about any other modern Linux server.  You’ll have to substitute “yum” for “dnf”, “apt-get”, or other software-management tools specific to your chosen distribution.  Also, some steps may not be required, and other additional steps may be required, depending on the default set of software installed.  Also, some commands and file content may need to differ from what I’ve presented here.

4.1.2Why Digital Ocean?

They are convenient, easy-to-use, provide a management API, and offer a USD5/month plan that is perfectly adequate for starting your own cloud server.  There are many other providers (eg: Linode); feel free to shop around and choose something to your liking.

4.2Preparing the host

We’ll be installing a few things that make the process a little easier, and setting up basic server settings.

Further commands can be run inside a screen session; this way, if you are disconnected from the server then any command you were running at the time won’t be aborted.

4.3Installing the web server

We’ll be installing Apache 2, and PHP 7.  Apache will be configured with SSL support.

4.4Setting up an SSL certificate

Thanks to the Let’s Encrypt project, it’s now trivial to generate your own free SSL certificates.  We’ll install CertBot to do the grunt work, and enable SSL in Apache.

4.5Installing IMAP

IMAP is a protocol that can be used to access your email on a server.  We’ll be setting it up so that we can back up our SMS messages and phone call logs.

Although we haven’t shown how to do so here, it’s possible to connect a mail client (such as Thunderbird) to the IMAP service on your mail server in order to access your SMS messages or organise them into folders.  Note that if you organise them into folders, they won’t be restored to your phone if you restore to a new or factory-reset device.

4.6Installing the database software

Although Nextcloud supports the use of a convenient database called Sqlite, you’ll get scalability and better performance by using MySQL or a fork of it known as MariaDB.  We’ll be installing MariaDB, securing it, and preparing it for Nextcloud.

4.7Installing Nextcloud

Now is the interesting part!  Here’s where we finally install Nextcloud.  You should run these commands either from root’s home folder (/root) or from the web-server’s home folder (/var/www)

4.8Post-install tasks

 

5Setting up your device

5.1Preparing your device

Note that this is optional; if you are happy to use whatever Android installation comes with your device, go right ahead and skip to the next sub-section.  Note that some devices have been configured in such a way that you actually must add a Google account before using the device.  This seems to be something that the manufacturer can control, since not all devices have this requirement.

Here’s the recommended process for preparing your device (note that the steps are device-specific, and are beyond the scope of this documentation; also, you may choose to skip some steps or do something entirely different in order to achieve the same thing):

  1. 1.Download and install ADB and Fastboot for your desktop computer (Google can help you find the right version for Windows; if you use a Linux desktop, your distro’s software installation tool can probably help) 

  2. 2.Download TWRP and  LineageOS for your device 

  3. 3.Unlock your device’s bootloader 

  4. 4.If you want to back up your device’s stock recovery before replacing it with TWRP, use fastboot boot to run TWRP before installing it and back up the recovery partition 

  5. 5.Install TWRP 

  6. 6.Back up the factory ROM 

  7. 7.Copy the recovery and ROM backups from your device to somewhere else 

  8. 8.Install LineageOS 

During the first boot (either after installing LineageOS or after a factory reset), consider enabling Privacy guard; this blocks any attempts by apps from accessing your private data.  It can be a bit irritating the first time each app asks for access to something, but you typically choose “always”, “never”, or “ask me each time”; by choosing “always” or “never”, you’re only asked the once for each permission for each app.

5.2Installing packages

5.3Connecting your device to Nextcloud

This sets up file synchronisation, so that you can share files between your device(s) and your server.

5.4Setting up calendar and contact synchronisation

This connects Android’s built-in calendar and contact apps to your Nextcloud server.

5.5Setting up SMS and call-log backup

SMS Backup+ can back up your SMS messages and phone call logs to IMAP folders.  SMS Backup+ can also save phone call logs to a calendar, making it easy to see your call history in Nextcloud or on your device.

6Troubleshooting

Apache log files:

NextCloud log files:

Test connection to imaps:

7Maintenance

7.1Backing up your cloud-hosted data

7.2Other?

8Recovery and other tasks

8.1Recover from server failure

8.2Recover from phone loss or failure

8.3Migrate cloud-hosted data to a new server

9Security considerations

It might be better to configure SELinux properly, rather than disabling it.  Here’s a possible starting point for this: https://www.marksei.com/install-nextcloud-12-centos-7/

10Additional notes

10.1Hosting notes

In general, you should be able to set up online backup/sync/access of your device data to almost any type of hosting arrangement in almost any location.

10.1.1Hosting locations

Here are some possible hosting locations:

SSL note: Note that internal-only or VPN-only access might make it difficult to issue and maintain SSL certificates via Let’s Encrypt since Let’s Encrypt needs to reach your server in order to verify the hostname.  You may still be able to buy and use a certificate using a traditional SSL certificate provider, though.  Let’s Encrypt should work OK with DMZ or port-forwarding configurations.

Internal hosting note: If you host Nextcloud internally with access externally (either via DMZ or port forwarding), you may have issues connecting internally using the external hostname.  If this is the case, either find a firewall/router that supports hair-pin routing, or set up the hostname to resolve internally to the correct internal IP address.

10.1.2Hosting environments

Nextcloud and other tools used in the server side of this setup should work on just about any conceivable modern Linux distribution, and could probably be made to work adequately on Windows.

10.1.3Server configurations

This setup is hardware-agnostic, and so could work on any of these types of system and more:

10.1.4Multi-device and multi-user arrangements

You could add users to Nextcloud and/or IMAP to support multiple devices and/or multiple users.  Here are a few possibilities:

 

10.2References

Server setup stuff:

 

Server setup caveats:

 

11Future improvements