Got a NAS? Still store your photo library and digiKam databases on a local machine? It’s time to take your digiKam setup to the next level by moving your photo library to the NAS and switching to the MariaDB (or MySQL) database backend. This allows you to access your photo library from any machine on the same network as well as keep your photo library safe thanks to the fact that storage on most NAS appliances is usually configured as RAID.
Switching to the NAS-based digiKam setup is a three-step process:
- Switch to the MariaDB database backend
- Enable and configure Samba
- Move the photo library to the NAS
Before you proceed, though, you need to do some preparatory work. First of all, you need a fast network link between the NAS and any machine that you want to use for working with your photo library. Even the fastest WiFi connection is simply not fast enough, so a wired network connection is the only viable option here. However, laying Ethernet cables around your apartment might not be particularly practical. In that case, a couple of Gigabit powerline network adapters provide a less cumbersome solution. Keep in mind, though, that if any of your neighbors get the same idea of using powerline adapters on their local networks, this will affect the overall speed of your network too.
While many NAS models ship with the MySQL/MariaDB database server, you often need to activate it manually. To do this on a QNAP NAS, launch the Control Panel, click SQL Server in the Applications section, and activate the Enable SQL server and Enable TCP/IP networking options. Press Apply to start the MariaDB server.
To manage the server and databases, install the phpMyAdmin application from the App Center. Next step is to create a new database user as well as databases for use with digiKam. To do this, launch phpMyAdmin, switch to the Databases section, and create three databases: digikam, digikam-thumbnails, and digikam-recognition. Switch then to the User Accounts section and create a new user by clicking on Add user account. Specify the desired user name and password. Choose Any host from the Host name drop-down list. Enable the Global privileges → Check all option, and press Go.
Now it’s time to switch digiKam to the MariaDB database engine. To be on the safe side, back up the digiKam databases first. Launch then digiKam, choose Settings → Database Migration and use the migration tool to move the existing digiKam databases to MariaDB.
Next step is to mount a remote NAS directory on the local machine storing your photo library. Practically all NAS appliances on the market support the SMB protocol, so you can use it to mount a remote directory on your machine. Assuming that the SMB server is up and running on the NAS, you can use the following command to mount the desired remote directory into the local folder:
sudo mount -t cifs //ipaddress/path/to/dir /path/to/local/dir -o user="user",password="password",uid=$(id -u),gid=$(id -g)
Replace the example values as follows:
- ipaddress – the actual IP address of the NAS (e.g., 192.168.178.47)
- /path/to/dir – path to the directory on the NAS. This is going to be the new location for your photo library.
- /path/to/local/dir path to the directory on the local machine where you want to mount the remote folder
- user SMB user name (usually an existing NAS user name)
- password password of the specified user
In digiKam, choose Settings → Configure digiKam and switch to the Collections section. Use the Add Collection button next to Collection on Network Shares to add the mounted folder as a new collection, then click OK. Move the existing albums into the new collection. Once you’ve done that, go back to the Settings → Configure digiKam → Collections section and remove the emptied local collections. Congratulations, you are done!
Automate Mount and Backup Actions
Since your photo library sits now on the NAS, you need to mount it on your local machine before you can launch digiKam. Doing this manually can quickly become a nuisance, but you can easily automate this task by writing a simple Bash shell script:
#!/usr/bin/env bash if [ ! "$(ls -A /path/to/local/dir)" ]; then sudo mount -t cifs //ipaddess/path/to/dir /path/to/local/dir -o user="user",password="password",uid=$(id -u),gid=$(id -g) digikam else digikam fi
Save the script under the digikam-launch.sh name and make it executable using the chmod +x digikam-launch.sh
command. Since the mount
command in the script requires root privileges, the script prompts you to enter the root password every time you run it. To prevent this from happening, add mount
to the sudoers list. To do this, use the which mount
command to find out the exact path to the mount
tool (e.g., /usr/bin/mount). Run the sudo visudo
command, and add the following line at the end of the sudoers file (replace user with your user name on the local machine):
user ALL = NOPASSWD: /usr/bin/mount
Save the changes, and you are done. You can then assign a keyboard shortcut to the script, so you can launch digiKam using a key combination.
Now that digiKam stores all its data in MariaDB databases, it makes sense to back them up on a regular basis. And a quick-and-dirty shell script can help you with that.
#!/bin/bash NOW=`date +%Y%m%d` USER="user" PASSWD="password" HOST="localhost" DIR="/path/to/backup/dir" DB="digikam digikam-thumbnails digikam-recognition" mkdir -p $DIR mysqldump -u$USER -h$HOST -p$PASSWD \ --databases ${DB} > $DIR/$NOW-digikam-db.sql cd $DIR tar -zcvf $NOW-digikam-db.tar.gz $NOW-digikam-db.sql rm $NOW-digikam-db.sql
Replace the example values with the actual MariaDB user name, password, and host. Specify also the path to the directory for storing backups. Note that on some NAS appliances like QNAP, you need to specify the absolute path to the mysqldump tool. To find out the absolute path, run the find / -name mysqldump
command. Save the script on your NAS and make the script executable. When you run the script, it should create a .tar.gz backup file in the specified directory. To run the script on a regular basis, add a cron job.
This is an excerpt from the digiKam Recipes book. Get your copy from Google Play Store or Gumroad.
Hi Dimitri!
Thanks for the tutorial. One question: is the Maria/MySQL backend already considered as stable? I thought I read something about tackling the DB backend in the upcoming version 6.0 of digikam.
For the Automount: I’d suggest something like Systemd Automount or Autofs instead of doing sudo in a bash script. This also works application independent so one can also access the NAS share from the commandline or a regular filemanager
Thank you for your comment! In digiKam 5.9.0, MySQL support is still marked as experimental. But so far, I had no issues at all. You are right regarding the automount.
Great tutorial!! Plenty of knowledge and real case workarounds!!
Thank you
Have you tried NFS instead of CIFS? It is more native to Linux.
I wonder about the responsiveness of DK in this scenario? It is ok to put photos on NAS but DB with thumbnails? The speed of NAS is not very impressive (comparing to SSD as local drive). And NAS as mysql server makes me even more doubtful. Have you noticed difference in speed?
I’m using Synology (simple home version) as album datastore. DB is on local drive.
P.
I’m using the described setup. It’s definitely not as fast as having the database and the photo collection on the local disk, but it’s fast enough for everyday use. Yes, I tried NFS, but it was actually slower than SMB. Not sure why.
Can this setup deal with multi-user parallel working on different PCs? For example two users work to tag photos with keywords / … ?