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.

No comments:

Post a Comment