2022年8月27日 星期六

[nextcloud, iphone] How to setup a private storage service for automatically sync up your iPhone Photo/Video

How to setup a private storage service for automatically sync up your iPhone Photo/Video

井民全, Jing, mqjing@gmail.com

這裡介紹 NextCloud 如何做到一樣的事, 也就是把手機的照片與影片備份到家裡硬碟,而且能夠隨時在手機上看到照片. NextCloud 是原先  owncloud 的創辦人, 因為理念不合, 另外創辦的公司, NextCloud 與 OwnCloud 共用早期呃程式碼, 但分支後, NextCloud 有更多的整合應用, 例如: Talk, Status, Calendar, Mail 系統.

我一直覺得,自己可以架設一個類似 Google Photo 的系統, 因為 Google 免費, 就一直擱著, 現在既然 Google 要收回免費的服務, 那麼正好就來試試安裝設定一下.  讓家裡的儲存空間與手機的照片庫, 自動同步備份. 徹底解決照片分享、備份、手機容量的問題. 

資料儲存最重要的就是要讓人安心, 也不用擔心, 因為斷電或其他意外, 使得 NextCloud docker instance crashed 造成資料無法消失,. 


NextCloud Docker 版的所有東西, 全部都會放在 host 的 volume 目錄中, 你隨時可以用你熟悉的方式做備份. 你的資料完全看得到, 摸得到. 

In this document, I'll show how to install a simple NextCloud server and use the iPhone App "Next Cloud" to automatic backup the photos and videos to the next cloud volumes.

For backup solution, the moet important question is Where is my data stored? Here, Next Cloud provide not only a integrated interface for upload but also a original folder form for your data, photo, and video files. 

We can see the Data

For example, you can easy find out a user jing's all data/photo/video at the following location,  and the .../data/jing. Know the location, you can use your familiar way to backup your data.

Data is saved even the system crashed

All data in Next cloud are stores in the unnamed docker volume volume /var/www/html. The docker daemon stores data within the docker directory /var/lib/docker/volumes/.... That means your data is saved even if the container crashes, is stopped or deleted.

Here is the procedure.

1. Server Site

1.1. Requirement

Platform

Options

OS

  • Ubuntu 20.04 LTS (recommended)

Database

  • MySQL 8.0+ or MariaDB 10.2/10.3/10.4/10.5 (recommended)

Webserver

  • Apache 2.4 with mod_php or php-fpm (recommended)

  • nginx with php-fpm

PHP Runtime

  • 8.0 (recommended)

In this document, I will use Ubuntu 22.04 LTS for testing. It's ok and can be successful to install.

1.2. Install Docker

# install

sudo apt-get install curl -y

sudo curl -sSL https://get.docker.io/ | sh


# check

docker -v


# add $USER to the docker group

sudo usermod -aG docker ${USER

su - ${USER# apply the new group membership


# check

groups   # check to see the docker group

docker run hello-world   # test the docker command


1.3. Install and Run NextCloud

sudo docker run \

--restart always \

--publish 80:80 \

--publish 8080:8080 \

--publish 8443:8443 \

--volume nextcloud:/var/www/html \

nextcloud:stable


# verify

http://localhost/



For more options, you can reference the Quick Reference Guide[3]. 

Q: If I want to edit config.php, where is the nextcloud?

=> Check the host folder at /var/lib/docker/volumes/nextcloud/

Verify

Get an other machine and launch a browser to the http://[nextcloud-ip].

2. Dashboard

To see the status

3. Configuration

3.1. How about the servier crashed or restart? 

Quick response: They are located at the host folders and will not to be destroyed after the docker instances removed or crashed or restart. 

From the document[2], 

The Nextcloud installation and all data beyond what lives in the database (file uploads, etc.) are stored in the unnamed docker volume volume /var/www/html. The docker daemon will store that data within the docker directory /var/lib/docker/volumes/.... That means your data is saved even if the container crashes, is stopped or deleted.

That means, all your data was stored at the host location, /var/lib/docker/volumes/. If you want to edit the config.php, at host, you can edit the folder /var/lib/docker/volumes/nextcloud/_data/config/config.php. Don't forget sudo.

e.g.

3.2. Where is my Data?

For users admin and jing, you can check the folder /var/lib/docker/volumes/nextcloud/_data/data/admin and the .../data/jing. Check the examples was listed at below.



3.3. Edit config.php

vi /var/lib/docker/volumes/nextcloud/_data/config/config.php

Verify

Step 1: Enter the next cloud instance

sudo docker ps

sudo docker exec -it ${container-id} bash


Step 2: Check the config.php in the service environment

cat /var/www/html/config

Result: PASS


4. iPhone App

4.1. Install the App

Step 1: Install the NextCloud App from AppStore

Step 2: Login to your NextCloud server



If everything is ok, you will see these ... 

4.2. Configuration to Auto upload photo and video

Click the [More] at the bottom and then select the [Settings]


5. Testing

5.1. Scenario 1: Restart the service

Instructions

sudo docker stop [server-id] and then start the [servier-id]

Result: Pass. All data reserved.


5.2. Scenario 2: Reinstall the service

Instructions

sudo docker rm [server-id] and sudo docker image rm [image id

install the service, again


sudo docker run \

--restart always \

--publish 80:80 \

--publish 8080:8080 \

--publish 8443:8443 \

--volume nextcloud:/var/www/html \

nextcloud:stable


# verify

http://localhost:8080/


Result: Pass.  All data reserved.


6. Maintenance

For occ command, the page, https://docs.nextcloud.com/server/latest/admin_manual/maintenance/index.html

6.1. Where to run the occ command

Step 1: Into the the Next cloud docker instance

sudo docker ps

sudo docker exec -it ${container-id} bash

e.g.:

Get the container id of the NextCloud is a6..... and then into the instance.

Step 2: Get the www-data user id

# try to run occ command to list user

php ./occ user:list

e.g..

Step 3: Using the right user id run occ command, again

sudo docker exec -it -u 33 a6 bash

E.g.


6.2. Install OCCWeb

Step 1: Launch a Browser: login to the server

Step 2: Install the OCCWeb

User: admin -> Apps -> Tools: OccWeb

 


Step 3: test OCC command

6.3. Maintenance Mode

(link)


6.3.1. Setup the maintenance mode

From the document, enable the maintenance mode will locks the sessions of all logged-in users, including administrators, and displays a status screen warning that the server is in maintenance mode. Users who are not already logged in cannot log in until maintenance mode is turned off. When you take the server out of maintenance mode logged-in users must refresh their Web browsers to continue working.

However, I got issues prevent me to run occ on the host. So, my alternative method is directly modify the config.php file. There are some interestings options can be setup such as Preview option: OC\Preview\HEIC, OC\Preview\Movie, OC\Preview\PDF, OC\Preview\JPEG; Maintenance options, SSL option, Store files in a swift object storage. 


If you are interesting more options in config.php, you can reference to the config paramenters.

Step 1. Edit the config.php

Command

sudo /var/lib/docker/volumes/nextcloud/_data/config/config.php

File: /var/lib/docker/volumes/nextcloud/_data/config/config.php

<?php

$CONFIG = array (

  'maintenance' => true,

  'htaccess.RewriteBase' => '/',

  'memcache.local' => '\\OC\\Memcache\\APCu',

  'apps_paths' =>

  array (


...

e.g.

Result


6.3.2. Turn the Maintenance Off

Remove the  'maintenance' => true from the config.php


6.4. Backup


# backup folder

rsync -Aavx nextcloud/ nextcloud-dirbkp_`date +"%Y%m%d"`/


# backup database

sqlite3 data/owncloud.db .dump > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak


# backup 


6.5. Restore


7. References

  1. https://github.com/nextcloud/all-in-one#how-to-use-this

  2. https://github.com/docker-library/docs/blob/master/nextcloud/README.md#persistent-data

  3. The Quick Reference Guide, https://github.com/docker-library/docs/blob/master/nextcloud/README.md

  4. OCCWeb, https://apps.nextcloud.com/apps/occweb

  5. Using the occ command, https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html

  6. Mainentance occ commands, https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#maintenance-commands

  7. Configure.php, https://docs.nextcloud.com/server/22/admin_manual/configuration_server/config_sample_php_parameters.html




8. Development

  1. NextCloud/OwnCloud, dev, sheet