Horizontal Navigation

Friday 7 October 2022

Daily Automatic DSpace Backup of Database & Repository

The detailed procedure to take daily automatic DSpace backup of Database & Repository using DSpace Backup Commands in Terminal.

In this process, we will create DSpace backup file for the following:

      1. PostgreSQL Database.

      2. DSpace File System (dspace/assetstore directory).

      3. DSpace Log Files. (dspace/log directory).

To set up Automatic Daily DSpace Backup, Please do follow the below DSpace Backup Commands.

First of all, log in to the root user and create a directory for backup.

sudo su

Enter Login password when prompted.

mkdir dspace_backup

Allow permissions to this newly created folder.

sudo chmod 777 dspace_backup

Next, exit from root directory.

exit

Now Create a script file for automatic dpsace backup. 

sudo nano dspace_backup/backup.sh

Copy below text into file and save it.

#!/bin/bash
PGPASSWORD="dspace" pg_dump -U dspace -h localhost -Fc dspace | gzip > dspace_backup/dspace-$(date +%Y-%m-%d-%H.%M.%S).sql.gz
now=$(date +"%d_%m_%Y")
zip -r  /home/server/dspace_backup/$now-assetstore.zip /dspace/assetstore
zip -r  /home/server/dspace_backup/$now-log.zip /dspace/log

N.B.:Change [username] & [password] as per your DSpace Database Credentials.

Make this file executable by the following command:

sudo chmod +x dspace_backup/backup.sh

Now, execute this file for testing by the following command:

sh dspace_backup/backup.sh

Next, Schedule DSpace backup using a cron job, Open Crontab using nano editor.

crontab -e

It will ask to select an editor to open crontab, select nano editor.

Copy & paste the following lines at the end of crontab.

15 16 * * * dspace_backup/backup.sh

00 14 * * * find dspace_backup/* -mtime +180 -exec rm {} ;

Save this file using Ctrl+O and ENTER, then press Ctrl+X to exit the cron.

Now, This cron job will take Backup of Dspace Database, files & logs  automatically at 04:15PM daily and save it to dspace_backup folder. It will automatically delete backup files older than 180 days. 

Tuesday 1 September 2020

Installation of Dspace 6.3 on Ubuntu 20.04

 Step 0: Prerequisite Softwares for Creating Institutional Repository Using DSapce 

Must know, what is to be required for creating IR using DSpace:
1. Java Development Kit (JDK)
2. PostgreSQL Database
3. DSpace Software
4. Apache Ant (Pure Java Build Tool)
5. Apache Maven (Apache Build Automation Tool for Java Projects)
6. Apache Tomcat (Web Server for hosting Dspace) 
Open Terminal and execute following commands.  Use [Ctrl+Alt+T] to open Terminal.

Step 1: First update and upgrade your Ubuntu server and then Install All Prerequisite Softwares for creating Institutional Repository at your Institute. Use the following command.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install openjdk-8-jdk postgresql ant maven

Choose OpenJDK-8 as default by executing this command

sudo update-alternatives --config java 

Step 2: Create the database user. Please use the following command and follow the instructions.

(i) sudo su postgres
(ii)createuser -U postgres -d -A -P dspace


Enter password for new role: [Enter a password e.g. dspace]

Shall the new role be allowed to create more new roles? (y/n) n
[Enter n and press enter button]

Type exit


Step 3: Allow the database user (dspace) to connect to the database

Open the file "pg_hba.conf" by using the following command.
[If the following command not open, check the postgresql version number and apply in the command]

(i) sudo nano /etc/postgresql/12/main/pg_hba.conf

Add this line to the configuration file at the end:  

local all dspace md5

save and close the file


(ii) Restart PostgreSQL :


/etc/init.d/postgresql restart


Step 4: Create Dspace user and Dspace Installation Directory:
Execute the following commands one by one. 

(i) sudo useradd -m dspace
(ii)sudo passwd dspace
 [enter a password for the new user dspace]
(iii)sudo mkdir /dspace
(iv) sudo chown dspace /dspace


Step 5:
 Create the PostgreSQL 'dspace' database and extension pgcrypto:

sudo su dspace 
createdb -U dspace -E UNICODE dspace  

Then type exit and come to root user
 
sudo su postgres


Now type the following command to create extension pgcrypto (simply copy & paste the following command in your command line interface)
psql --username=postgres dspace -c "CREATE EXTENSION pgcrypto;"
 

Type the following to restart postgres:
/etc/init.d/postgresql restart


Step 6: Create Dspace Source directory and give permission to it:


sudo mkdir /dspace_build
sudo chmod -R 777 /dspace_build


Step 7: Download Dsapce to /dspace_build directory:
Execute the following command to proceed.

(i) cd /dspace_build

(ii) Then simply Copy and paste (use the mouse only) following line in the terminal.


wget https://github.com/DSpace/DSpace/releases/download/dspace-6.3/dspace-6.3-src-release.tar.gz


(iii) Extract Dspace package by using the following command:


tar -zxf dspace-6.3-src-release.tar.gz

Step 8: Open the following file and comment the code block:
Execute the following command to proceed.

nano /dspace_build/dspace-6.3-src-release/dspace-api/pom.xml
 

Carefully identify the following block of code and comment it:

<!--<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions><execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>-->

Step 9: Use the following command to run maven for the installation of Dspace in Installation Directory (/dspace):

(i) cd /dspace_build/dspace-6.3-src-release
(ii)mvn -U package 


Step 10: Enter into the Dspace package folder to download packages by issuing the following commands.


(i) cd dspace/target/dspace-installer
(ii)sudo ant fresh_install


Step 11: Installation of Tomcat (one more prerequisite software for DSpace):

Download and extract the Tomcat package. First, change the current directory to /opt Directory.

(i) cd /opt

(ii) wget http://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.45/bin/apache-tomcat-9.0.45.tar.gz

(iii) tar -xvzf apache-tomcat-9.0.45.tar.gz

(iv) Rename folder "apache-tomcat-9.0.45" to "tomcat". Issue following command to do so.

mv apache-tomcat-9.0.45 tomcat


(v) Delete the package file from /opt folder. Issue the following command to do so.


rm apache-tomcat-9.0.45.tar.gz


Step 12: Open following file "/etc/profile" and edit:

(i)gedit /etc/profile

Setup environment variables
Environment variables to find JAVA.
Add following lines at the bottom of the file

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export CATALINA_HOME=/opt/tomcat

Then Save and close file.
Step 13: Copy Dspace webapps files (web deployment directory) to Tomcat folder 

sudo cp -r /dspace/webapps/* /opt/tomcat/webapps


Step 14:
 Give permission to tomcat owner, so that tomcat can be executed by dspace user by applying following command:
(i) cd /opt
(ii)chown dspace.dspace tomcat/ -R


Step 15: Start Tomcat server:

Use following command to start tomcat server.

/opt/tomcat/bin/startup.sh

 If you want to stop Tomcat server, then use following command:


/opt/tomcat/bin/shutdown.sh

Step 16: Make an initial administrator account (an e-person) in DSpace:


Apply following command in a terminal,

 
/dspace/bin/dspace create-administrator

It will ask to enter email address for user login.

Enter an email address (e.g. dspace@localhost).
Enter First name and surename (e.g. dspace)
Enter a password.

Step 17: Open Dspace in your browser

You can load either one Dspace interface in a browser.

http://localhost:8080/xmlui
http://localhost:8080/jspui


References: 

1. https://wiki.duraspace.org/display/DSDOC6x/Installing+DSpace