Android and linux sync

Set Up Android Two-Way File Synchronization with GNU/Linux

Summary

This tutorial describes how to set up two-way file synchronization between a device running Android and a GNU/Linux computer. The steps use Free Software, do not use or share your data with external service providers, and work with the stock «non-rooted» Android image.

The primary purpose of creating this tutorial was to replace Palm OS Memo synchronization capability with something similar on Android. The final solution enables two-way synchronization of memos contained in text files between a folder on Android and a folder on GNU/Linux. The tutorial is also useful for anyone who wishes to synchronize file changes between Android and GNU/Linux.

This tutorial is the third in a series exploring the replacement of my ageing Palm OS device with a device running Android. The other articles are Migrating from Palm OS to Android — The Journey Begins, and Set Up Android Calendar and Contacts with DAVdroid Sync to Radicale Server on Linux.

The steps in this tutorial were developed using Android 4.4.4 (KitKat) and Kubuntu 12.04 (Precise Pangolin) GNU/Linux. The steps should be useful for other distributions with some minor modifications. For example on Fedora replace the debian package manager apt-get with the fedora package manager yum or dnf . On openSUSE use zypper .

For an alternative file sync method that does not adb-sync and developer mode on your phone and instead uses Syncthing see Set Up Android File Synchronization with GNU/Linux Using Syncthing.

Contents

How Palm OS Memo Hot-Sync Worked

When a Palm Pilot was used in conjunction with J-Pilot on GNU/Linux, the combination enabled two-way synchronization of memo creations, modifications and deletions.

This meant that if a memo was created, edited, or deleted on the Palm Pilot, then these changes would be propagated to your GNU/Linux computer the next time the device was hot-synced with J-Pilot. The reverse was also true for changes made in J-Pilot.

The hot-sync process was initiated with the following steps:

  1. Connect Palm Pilot to GNU/Linux computer with USB cable
  2. Start J-Pilot on GNU/Linux
  3. Press Hot-Sync button on Palm Pilot cable (or button in Hot-Sync app)
    Note: If the device was locked, a pass-code would need to be entered
  4. Click Sync button in J-Pilot application
  5. Let the two computers synchronize any changes since the last hot-sync

Two-way synchronization was very handy for ensuring that memos were backed-up and available in both locations.

So far I have not found anything quite as elegant for Android. Having said that, I believe I have found an adequate solution which is described in the remaining tutorial steps.

Choose Text Editors for GNU/Linux and Android

Palm OS memos are essentially text notes identified with a title (the first line) and stored under a category. Changes to memos can be synchronized between the Palm OS device and a desktop or laptop computer.

On Android we can replace this functionality by using text files for the memos. To simulate the Palm OS environment I use a folder name for the Palm OS category and a file name for the memo title. Changes in these text files can then be synchronized between Android and GNU/Linux. This means we need a text editor on Android and on GNU/Linux in order to view and edit the text files.

Читайте также:  Android studio database inspector flutter

GNU/Linux provides many text editors, such as kate, gedit, emacs, and vi. I imagine that you already have a favourite (mine is emacs) so I leave the decision of what to use on GNU/Linux to you.

Fortunately Android also provides a broad choice of text editors. Personally I chose 920 Text Editor and installed it from F-Droid. Do feel free to test other text editors. The key thing is that the editor must be able to create, load, view, and save plain text files.

Install adb-sync on GNU/Linux

Prerequisite: The adb-sync program requires adb installed on GNU/Linux, and developer mode enabled on Android. If you have not already done this then see Installing Android Applications over USB.

Since there were no GNU/Linux packages containing adb-sync, I describe how to place the adb-sync script in your own bin folder.

Install the adb-sync file synchronization software:

Clicking the link should download the adb-sync-master.zip file into your

Open a terminal window.

In the K Desktop Environment (KDE) this can be done with the menu option: K -> System -> Konsole (Terminal).

TIP: Opening a terminal in other desktop environments

You can often open a terminal window using the following steps:

a) Press Alt+F2 to open a run command prompt
b) Enter «xterm» without the quotes

Create a bin folder in your home folder.

The purpose of the

/bin folder is emulate the way GNU/Linux commands are stored and discovered. The

/bin folder should be contained in the PATH environment variable so that executable files placed in

/bin will automatically be found. Note that the

(tilde) character represents the users home folder which is contained in the HOME environment variable.

/bin did not exist before, then you might need to logout and login so that executable files placed in

/bin/ are automatically found.

For example on login to my kubuntu 12.04 GNU/Linux distribution, if the

/bin folder exists then

/bin will be added to PATH. This occurs due to the following lines in my

—— Begin snippet from

—— End snippet from

If your distribution does not automatically find executable files placed in

/bin then you might need to edit

/.profile to ensure it contains lines similar to the above.

Extract the zip file contents into your

This will extract the contents of the zip file into an adb-sync-master folder under the

TIP: No unzip command?

To install the unzip command in Ubuntu use the following command in a terminal window:

sudo apt-get update && sudo apt-get install unzip

Create a symbolic link for adb-sync in your

The adb-sync program is now installed and should be invokable using the adb-sync command .

Create Synchronization Folders

We need a master folder to hold all of the subfolders that we wish to synchronize. I chose

/DroidSync as the name of my master folder. The reason for the master folder is to enable us to later use different modes of synchronization for subfolders (for example two-way or one-way synchronization).

Under the master folder we need a folder to hold all of our Palm Pilot memos. I chose Notes.

/DroidSync master folder.

Create Notes subfolder.

Later we will choose a location for the DroidSync file folder on Android.

Migrate Palm OS Memos from J-Pilot to Files

Now that we have a synchronization folder structure in place we can begin migrating memos into files.

Open J-Pilot and also a text editor on GNU/Linux.

For each memo in J-Pilot you wish to migrate:

Ensure the memo category subfolder has been created under

For example if you have memo stored under the category Personal on Palm OS, then create a Personal subfolder on GNU/Linux.

Copy the contents of the memo from J-Pilot into the copy buffer.

Paste the buffer into your favourite text editor.

Save the file under the title of the memo.

For example if you have memo titled Famous Quotes under the Personal category then save the file contents under the category subfolder

/DroidSync/Notes/Personal with the Famous-Quotes.txt file name.

Repeat the above steps for each memo you wish to migrate.

Create droidsync Script

Now that we have our memos stored in folders and text files under the

/DroidSync/Notes folder, we need to create a shell script to perform the file synchronization. Note that the script also makes a backup on GNU/Linux of the application package names installed on Android.

Use your favourite GNU/Linux editor to create a new droidsync file under the

Copy the following droidsync script lines and paste the lines into your editor.

Choose a location for the DroidSync folder on Android.

  • /storage/sdcard0 is internal memory
  • /storage/sdcard1 is a microSD card I installed

I choose /storage/sdcard1, which is reflected in the above droidsync script by the following line:

If you do not have a microSD card installed, then be sure to change the DROIDDIR to /storage/sdcard0/DroidSync. For example:

Save the file and exit the editor.

Make the droidsync script executable.

Run the droidsync Synchronization Process

Initiate the synchronization process with the following steps:

  1. Connect Android to GNU/Linux with USB cable
  2. Enter pass-code on Android if device is locked
  3. Open a terminal window on GNU/Linux
  4. Start droidsync script

If droidsync script is not automatically found then you might need to update your

/.profile script to add

/bin to the PATH as described in step 3 of Install adb-sync on GNU/Linux.

  • Click Allow USB permissions if prompted on Android
  • Let the two computers synchronize creations and/or modifications since the last synchronization
  • Note that file deletions are not synchronized. Instead the file is re-created on the computer from which it was deleted.

    To work around this minor issue, ensure the file is deleted on both Android and GNU/Linux before running the synchronization process.

    File Synchronization Set Up Complete

    Congratulations! You’ve finished setting up file synchronization between Android and GNU/Linux.

    Now files that you create or edit under the DroidSync/Notes folders on Android or GNU/Linux will be duplicated on the GNU/Linux or Android repectively whenever you run the droidsync synchronization process.

    Appendix A: Other Ways to Use adb-sync

    The adb-sync program is very flexible. Not only does it permit two-way synchronization, but also one way with either Android or GNU/Linux being the master and the other the slave.

    One-Way Android to GNU/Linux Synchronization

    In this scenario we use Android as the master source and have changes pulled to GNU/Linux.

    This is useful for example to back up a spreadsheet you maintain on Android in /storage/sdcard1/DroidSync/Spreadsheets.

    Create /storage/sdcard1/DroidSync/Spreadsheets.

    Use a file manager in Android, such as Simple Explorer, to create /storage/sdcard1/DroidSync/Spreadsheets.

    Add lines to the droidsync script similar to the following:

    Be sure to save your Android spreadsheets in the /storage/sdcard1/DroidSync/Spreadsheets folder.

    One-Way GNU/Linux to Android Synchronization

    In this scenario we use GNU/Linux as the master source and have changes pushed to Android.

    This is useful for example when you find and store eBooks on GNU/Linux in DroidSync/Books but wish to read these on Android.

    Add lines to the droidsync script similar to the following:

    Be sure to copy your eBooks to the

    Appendix B: Why I Chose adb-sync for File Synchronization

    Usually for file synchronization duties I use tools such as unison or rsync. These tools require either a remote service or remote file system access to synchronize files and directories.

    For the companion unison or rsync remote service applications on Android, these unfortunately appear to either require root privilege, or a non-free software application.

    For remote file system access Android provides the Media Transfer Protocol (MTP). Fortunately several free software tools are available under GNU/Linux that provide file system access to MTP devices. Unfortunately the following two that I investigated had limitations.

    MPTfs is a FUSE file system that supports reading and writing any MTP device. Unfortunately the directory and file creation and modification dates are not correct or maintained. Directories always had the date of December 1969, and files had today’s date of creation.

    jmtpfs is a FUSE and libmtp based filesystem for accessing MTP (Media Transfer Protocol) devices. Unfortunately the directory and file creation and modification dates are not correct or maintained. In this case the directory dates behaved the same as the file dates and had today’s date of creation.

    In my testing with MTPfs and jmtpfs sometimes older file contents clobbered new file contents. As best I could discern, the synchronization appeared to give precedence to the larger file, and not the most recently edited file. Further hampering the use of MTP, there appears to be a bug in Android in that not all directories and files are shown using MTP until reboot.

    These above limitations prevented me from using unison or rsync, and prompted me to search for another solution.

    Fortunately I discovered adb-sync, which is free software that works with my non-rooted Android 4.4.4 kitkat device.

    References

    While researching how to migrate from Palm OS to Android I found the following references useful:

    Future Articles

    In a future article, I plan to cover the following topic:

    • Migrating Palm OS Keyring to Android

    Источник

    Связываем пк на linux с android смартфоном

    Здравствуйте, уважаемые читатели. Для пользователей linux есть одна занимательная программа, попробовав которую хочется использовать постоянно. Она называется KDE Connect. Программа позволяет связать смартфон на базе android с пк через шифрованный канал локальной сети или vpn соединение.

    Чем полезна программа?

    Программа дает возможность не отвлекаться на телефон во время работы за компьютером. Все ваши уведомления, напоминания, смс, пропущенные звонки будут отображаться на экране компьютера в виде всплывающих окошек.

    Если вы слушаете музыку и что-то ищете в интернете, то во время звонка плеер на компьютере ставится на паузу, а как только вы поговорите, воспроизведение снова продолжится. Очень удобная функция. А еще вы можете просто управлять вашим плеером через смартфон.

    Также присутствует полезная функция работы с смс. Вы можете не только видеть на экране пк, что пришло смс, но и ответить на него прямо с компьютера. Это удобно, когда на некоторых сайтах, требуется смс подтверждение.

    Шикарная функция общего буфера обмена. Выбрав на компьютере необходимую информацию вы копируете ее, а в своем смартфоне просто достаточно тапнуть и выбрать пункт вставить.

    И, конечно же, присутствует возможность обмена файлами между смартфоном и пк.

    И это лишь самые основные функции программы.

    Как начать пользоваться?

    Хотите попробовать? Отлично, вам всего лишь нужно выполнить два действия. Установить программу на компьютер и установить приложение в смартфон. С приложением все просто, заходите на Play Market и устанавливайте KDE Connect. Не забываем дать приложению все запрашиваемые им разрешения.

    Для того, чтобы установить программу на ваш linux, нужно просто обратиться к репозиториям вашего дистрибутива и ввести в поиск kdeconnect.

    Источник

    Оцените статью