Home | Send Feedback

Self-host Seafile

Published: February 04, 2019  •  linux

Seafile is an open source file sync and share software. You can upload files and sync them across different devices. Seafile provides a web interface but also native clients for macOS, Linux, Windows and for the mobile platforms Android and iOS. These clients share the files across the different devices, Seafile also provides drive clients that enable you to access files on the server without synching to local disk, like a network drive.

You can use Seafile by subscribing to a hosting provider. But in this tutorial we are going to self-host Seafile and install it on a LightSail server from Amazon. I'm testing this on the cheapest LightSail server that cost $3.50 and includes 20GB of disk space. If you are looking for VPS with much more disk space I recommend looking at Contabo: https://contabo.com/?show=vps
For 156 EUR a year you get a server with 1400 GB disk space. Quite a good deal if you compare that with Dropbox where you get 1 TB disk space for about 100 EUR.

In this tutorial I'm going to install the free Open Source Edition of Seafile. There is also a Pro Edition available which is also free for up to 3 users, but for this tutorial I don't need the additional features of the Pro Edition. Checkout this page to view the differences between Open Source and Pro Edition.

DNS

Before I start setting up the server I installed a subdomain. This is needed if you want to use TLS, which is highly recommended. For this demo I use the domain sea.ralscha.ch

In the web console of my DNS provider I inserted an A record that points to the IP address of my LightSail VPS.

sea.ralscha.ch.        86400   IN      A       51.38.124.133

I also recommend adding a CAA record, if your DNS provider supports this feature. Either for the whole domain if you get all your certificates from one CA or just for the subdomain if you use multiple certificate authorities.

ralscha.ch.             86400   IN      CAA     0 issue "letsencrypt.org"
// OR
sea.ralscha.ch.        86400   IN      CAA     0 issue "letsencrypt.org"

Docker

If you want to follow this tutorial and also use a Lightsail VPS, go to my previous blog post and follow the instructions until, but without, the section Install required packages. I selected Debian 9.5 as operating system.

Connect to your VPS and upgrade the installed packages

ssh -i lightsail admin@51.38.124.133
sudo apt update && sudo apt dist-upgrade

lightsail is the name of my private key file.

The easiest way to install Seafile is as Docker container. For that we need to install Docker first. For the Docker installation I follow the instructions on this page:
https://docs.docker.com/install/linux/docker-ce/debian/

sudo -i
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg2 \
    software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io
exit

You don't have to use Docker, you can install Seafile directly on Linux. Doing it this way has the advantage that you have full control over the Seafile installation.

Visit the official documentation page for more information about this topic:
https://manual.seafile.com/deploy/

Seafile

With a running Docker installation we can now pull the Seafile image and start it. For the following steps I follow the description from the Server Manual:
https://manual.seafile.com/deploy/deploy_with_docker.html

docker run -d --name seafile \
  -e SEAFILE_SERVER_LETSENCRYPT=true \
  -e SEAFILE_SERVER_HOSTNAME=sea.ralscha.ch \
  -e SEAFILE_ADMIN_EMAIL=me@ralscha.ch \
  -e SEAFILE_ADMIN_PASSWORD=a_very_secret_password \
  -v /opt/seafile-data:/shared \
  -p 80:80 \
  -p 443:443 \
  --restart unless-stopped \
  seafileltd/seafile:latest

Make sure that you specify the correct hostname, email and a secure administrator password. This docker command maps the data directory /shared inside the container to the /opt/seafile-data folder of the host computer. You may change /opt/seafile-data if you don't like this location.

Also make sure that you open the firewall ports on your VPS. For Lightsail you do that in the Web Management Console

firewall

If you are interested in installing the Pro Edition with Docker visit this page:
https://manual.seafile.com/deploy_pro/deploy_with_docker.html

Client

Your Seafile installation should be up and running. If you open the web interface in a browser, a login screen should appear.

https://sea.ralscha.ch
admin

As admin you can set up more users in the System Admin section.

The first time you start a native client he presents a dialog where you have to enter the server address and your login credentials. After that it syncs the remote library to your local computer and each time you add files locally it syncs them to the remote server.

settings

Upgrade Seafile

From time to time you should upgrade your Seafile installation. In order to do that you pull down the latest Docker image, delete the old container and then start the container with the new image.

docker pull seafileltd/seafile:latest
docker rm -f seafile
docker run -d --name seafile \
  -e SEAFILE_SERVER_LETSENCRYPT=true \
  -e SEAFILE_SERVER_HOSTNAME=sea.ralscha.ch \
  -e SEAFILE_ADMIN_EMAIL=me@ralscha.ch \
  -e SEAFILE_ADMIN_PASSWORD=a_very_secret_password \
  -v /opt/seafile-data:/shared \
  -p 80:80 \
  -p 443:443 \
  --restart unless-stopped \
  seafileltd/seafile:latest

Backup

Out of the box you usually don't have a backup on a VPS. Some VPS providers have snapshot tools where you can take a snapshot of the whole server. For a more mission critical Seafile installation you should look at installing a real time backup system, where you install Seafile on two servers and install a link between the two servers which copies everything from the main to the backup server in real time.

See the documentation for more information:
https://manual.seafile.com/deploy_pro/real_time_backup.html


In this section I show you a simplistic approach where a scripts runs once a day and copies everything to a Amazon S3 bucket.

If you follow this tutorial, first request the necessary access_key and secret_key from Amazon by following the steps in my previous blog post

Make sure that the policy you install contains the following 5 actions. The script utilizes s3cmd with the sync option which copies only changed files to S3, in order to do that it needs a bit more permissions than just PutObject.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:GetBucketLocation",
                "s3:DeleteBucket"
            ],
            "Resource": [
                "arn:aws:s3:::ralschaer.sefile/*",
                "arn:aws:s3:::ralscha.seafile"
            ]
        }
    ]
}

Install Amazon S3 command line tools.

sudo -i
apt install s3cmd 

In the /opt folder create a new script called backup-seafile and paste the following code.

#!/bin/sh
rm -fr /opt/seafile-backup
mkdir /opt/seafile-backup
cd /opt/seafile-backup
docker exec -i seafile mysqldump  -uroot --opt ccnet_db > ccnet_db.sql
docker exec -i seafile mysqldump  -uroot --opt seafile_db > seafile_db.sql
docker exec -i seafile mysqldump  -uroot --opt seahub_db > seahub_db.sql

cp -R /opt/seafile-data /opt/seafile-backup
cd /opt/seafile-backup/seafile-data && rm -rf ccnet

s3cmd --access_key=AKIA... --secret_key=l56SjC+... sync /opt/seafile-backup s3://ralschaer.sefile

Make the script executable

chmod 700 backup-seafile

Next, install a timer service in systemd. This takes care of starting our backup job daily at the specified time.

Create a file seafile-backup.timer and paste this code into the file.

[Unit]
Description=Run seafile-backup once a day

[Timer]
OnCalendar=*-*-* 05:00:00
RandomizedDelaySec=30
Persistent=true

[Install]
WantedBy=timers.target

Change OnCalendar if you want to run this script on a different time or more often than just daily. See the documentation for information about the supported format: https://www.freedesktop.org/software/systemd/man/systemd.time.html

Create the systemd service file seafile-backup.service and paste this code into the file

[Unit]
Description=backup-seafile

[Service]
WorkingDirectory=/opt
Type=oneshot
ExecStart=/opt/backup-seafile

Then link these files into the systemd folder, reload systemd, start and enable the timer

ln -s /opt/seafile-backup.timer /lib/systemd/system/seafile-backup.timer
ln -s /opt/seafile-backup.service /lib/systemd/system/seafile-backup.service
systemctl daemon-reload
systemctl start seafile-backup.timer
systemctl enable seafile-backup.timer

Check if the timer is installed properly

systemctl list-timers

Manually start the job.

systemctl start seafile-backup
journalctl -u seafile-backup

To recover a backup visit the chapter Recovery in the official documentation:
https://manual.seafile.com/deploy/deploy_with_docker.html


This concludes the tutorial about self-hosting Seafile. A powerful file sync software and a good alternative to Dropbox, Google Drive and others. Self-hosting software gives you more control over the data, but don't forget if you install something on a VPS that not only you have access to the data but also the VPS provider.