Thursday, December 18, 2025

Solving file upload issues in DSpace on Ubuntu

The Problem: Tomcat’s Security Sandbox

If you install Tomcat 9 or 10 using the default Ubuntu package manager (apt), it comes with strict security settings. Even if your folder permissions look correct on the surface, Ubuntu's systemd configuration prevents Tomcat from writing files to directories it doesn't explicitly "trust."

By default, Tomcat is blocked from writing to the DSpace folder. e.g. /opt/dspace, which is where DSpace needs to store uploaded content.

The Solution: Updating the Service File

I applied this solution to DSpace 7 & 8. To fix this, you need to tell the system that Tomcat has permission to write to your DSpace folder. Follow these steps:
Open the Service File: Find your Tomcat systemd unit file (usually located at /lib/systemd/system/tomcat10.service). Check the version of Tomcat.
Add the Path: Look for the [Security] section and find the lines starting with ReadWritePaths=. Add your DSpace installation path to this list. For example: ReadWritePaths=/opt/dspace
Check the User: Ensure the User= line in that same file matches the owner of your DSpace folder.

See how it looks after updating,

# Security
User=tomcat
Group=tomcat
PrivateTmp=yes
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
CacheDirectory=tomcat9
CacheDirectoryMode=750
ProtectSystem=strict
ReadWritePaths=/etc/tomcat9/Catalina/
ReadWritePaths=/var/lib/tomcat9/webapps/
ReadWritePaths=/var/log/tomcat9/
ReadWritePaths=/opt/dspace

Reload and Restart: Save the file, then run these commands to apply the changes:
sudo systemctl daemon-reload
sudo systemctl restart tomcat10
Once these changes are made, the "sandbox" is opened, and your file uploads should work immediately.

Reference

Saturday, February 15, 2025

How to automate the backup of DSpace database and folders

Here is a method to automate the backup of the PostgreSQL database and DSpace folders (e.g. assetstore) using a shell script and scheduling through cronjob.

Find the pg_hba.conf file change the method to 'trust'

The pg_hba. conf file resides within the PostgreSQL data directory and consists of a series of lines, each specifying a connection type, database, user, IP address, authentication method, and other details.
The file is located at Ubuntu 24.04 at /etc/postgresql/16/main/pg_hba.conf. Location may be different in Debian Linux. Check the location manually and open the file.

sudo mousepad /etc/postgresql/16/main/pg_hba.conf

Find the following lines and change the term peer to trust,

local   all             postgres                                peer
local   all             all                                     peer
host    all             all             127.0.0.1/32            peer

The output will look like this,

Save and close the file. Restart the PostgreSQL service.

sudo systemctl restart  postgresql

Make a shell script to take the backup

Create a backup folder on your computer. Apply the following command to create a local backup folder on your home folder. Change the location of the folder in the below command before applying it.

sudo mkdir /home/username/backup

The backup location can be a folder inside your cloud storage service like PCloud or Dropbox.
Open a new file inside the folder /usr/local/bin/ to create a shell script.

sudo mousepad /usr/local/bin/dspace-backup.sh

Copy the following content into the file. Make necessary changes in the file, e.g. location of the backup folder, PostgreSQL database name and user. 

#!/bin/bash
#backup of PostgreSQL database
BACKUP_DIR="/home/username/backup/"
FILE_NAME=$BACKUP_DIR`date +%d-%m-%Y-%I-%M-%S-%p`.sql
pg_dump -U db_user db_name > $FILE_NAME

# backup of assetstore folder
zip -r /home/username/backup/assetstore-$(date +%d-%m-%Y-%H.%M).zip /dspace/assetstore

#Delete older files more than 7 days will delete.
find /home/username/backup/* -mtime +7 -exec rm {} \;

Save and close the file.

Make the shell script executable

sudo chmod a+x /usr/local/bin/dspace-backup.sh

Add the crontab entry

Apply the following command to open crontab

sudo crontab -e

Copy and paste the following entries at the end of the editor.
Copy the below lines to the bottom part of the crontab file.

#DSpace backup
10 20 * * * /usr/local/bin/dspace-backup.sh

Change the timing of the backup. Here, backup takes at 8:10 PM.

If you want a backup every 5 hours, apply the following entry.

# DSpace backup
0 */5 * * * /usr/local/bin/dspace-backup.sh

Reference

Tuesday, October 8, 2024

Install DSpace 8 on Debian 12

Here, we use Debian 12 to install DSpace 8. If you don't like the Vanilla Debian, try PepperMintOS, / MX Linux / Linux Mint Debian edition. Beginners can find YouTube videos on how to install Debian Linux.

Prepare the system for Dspace installation

DSpace consists of both a Java-based backend and an Angular-based front end. Both the backend and front end need to be installed separately. Install the prerequisites for the DSpace software. Dspace builds on the Java platform and requires software packages like Tomcat, Solr, Maven, Ant, etc.

Monday, October 7, 2024

Install DSpace 8 on Ubuntu 24.04 LTS

Here, we use Xubuntu 24.04 LTS to install DSpace 8. Xubuntu 24.04 LTS loaded with Snap, which makes the system slow. In such cases, choose snapless Ubuntu-based Linux operating systems like Linux Lite / Rhino LinuxAsmi Linux.

Prepare the system for Dspace installation.

DSpace consists of both a Java-based backend and an Angular-based front end. Both the backend and front end need to be installed separately. Install the prerequisites for the DSpace software. Dspace builds on the Java platform and requires software packages like Tomcat, Solr, Maven, Ant, etc.

Wednesday, May 8, 2024

Add a new item type in item submission page in DSpace 7

Open the following file in a terminal:

sudo mousepad /dspace/config/input-forms.xml

Find the lines for item types.


Copy an existing code for an item type.

<pair>
       <displayed-value>Animation</displayed-value>
       <stored-value>Animation</stored-value>
</pair>

Add new value and paste between any default item types.

<pair>
       <displayed-value>PhD Theses</displayed-value>
       <stored-value>PhD Theses</stored-value>
</pair> 

Save and close the file.
Restart Tomcat and refresh the page to see the change.

sudo systemctl restart tomcat9.service

Tuesday, January 16, 2024

Change the text at DSpace 7 home page


Frontpage template available at [dspace-angular-frontend]\src\themes\dspace\app\home-page\home-news\home-news.component.html. The location of the dspace-angular-dspace may vary.

Open the template file using a text editor like Nano, e.g.

sudo nano /home/dspace/dspace-angular-dspace-7.6.1/src/themes/dspace/app/home-page/home-news/home-news.component.html 

Rebuild the production environment to take effect the changes.

Enter the location of the dspace-angular-dspace. Find the exact location of the [dspace-angular-frontend] and apply the following command. Here is an example of the command,

cd /home/dspace/dspace-angular-dspace-7.6.1/config

Apply the following command

yarn run build:prod

Refresh the home page of DSpace to see the changes made.

Thursday, February 23, 2023

Automate DSpace backups with Cron Task

Database backup

Open a Terminal and log in as a Postgres user,

sudo su - postgres

Create a directory in the Postgres user’s home to store the backups. Apply the following command,

mkdir -p ~/backups

Enter into the crontab:

crontab -e

Add the following entry into the Cron,

#DSpace Postgres backup

10 20 * * * pg_dump -U postgres dbname > ~/postgres/backups/dbname-$(date +%d-%m-%Y-%H.%M).bak

Change the timing of the backup, here backup take at 8:10 PM

Apply  CTRL + O button to save the cron entry.
Then apply CTRL + X to exit from the cron. 

Type exit to exit from Postgres prompt.

Backup of asset store and log folders


Open a terminal and apply the following command to create a folder in Home to hold asset store and log folders.

sudo mkdir dspacebkup

Open crontab to add the entry to automate the folder backup,
sudo su
crontab -e

Add the following lines,

10 20 * * * zip -r /home/vimal/dspacebkup/assetstore-$(date +%d-%m-%Y-%H.%M).zip /dspace/assetstore
10 20 * * * zip -r /home/vimal/dspacebkup/log-$(date +%d-%m-%Y-%H.%M).zip /dspace/log

Change the path based on your local setup.