How To Take Backup of Dspace Automatically on Dropbox

Let us know how to set a crontab to take schedule backup of Dspace in the dropbox (Cloud storage)

Install the Dropbox app on your Ubuntu machine

(Dropbox provides 2 GB of cloud storage that lets you save files online and sync them to your devices. After installation of the Dropbox app, A dropbox folder appears in the home directory of the Linux machine. we can add the files, and folders in the dropbox folder, which can be accessed from anywhere through the internet connection)
/Signup into the Dropbox account

1. Backup using a Simple backup script:-

Now open the terminal (ctrl+alt+t) 
Apply the below command

sudo su (Hit enter)

Enter Password

Open the Cron table

crontab -e

Select nano editor to open the file, go to the bottom of the file with the help of the down arrow and add the following lines.

10 17 * * * zip -r /home/dspace/Dropbox/ /dspace/assetstore
10 17 * * * zip -r /home/dspace/Dropbox/ /dspace/log

Locate the path of your Dropbox folder in the script carefully.

after then apply ctrl+x to exit and press the 'Y' button to save the change.

Your Backup will store every day at 05:10 PM in the Dropbox folder. You can locate it from anywhere using your Dropbox account.

2. Backup using bash script:-

Open the terminal 

sudo su (Hit Enter)

Enter the Password

Make a folder for backup

mkdir backup_dspace

Give the permission to a backup folder

sudo chmod 777 backup_dspace 

Create a script file to backup 

Open the file with your favorite editor (here I am using gedit  editor)

sudo gedit backup_dspace/

Add  the following lines to the file


PGPASSWORD="dspace" pg_dump -U dspace -h localhost -Fc dspace | gzip > backup_dspace/dspace-$(date +%Y-%m-%d-%H.%M.%S).sql.gz

now=$(date +"%d_%m_%Y")

zip -r  /home/dspace/backup_dspace/$ /dspace/assetstore

zip -r  /home/dspace/backup_dspace/$ /dspace/log

Change the Username and Password as yours DSpace database and give the right path of your backup folder.

Give the permission for execution

sudo chmod +x backup_dspace/

Execute the file, Run the following command

sh backup_dspace/

Now open the Crontab for automatic backup

crontab -e

select nano editor  to open it.

Add the following lines at the bottom in the file

30 17 * * * backup_dspace/

00 17 * * * find backup_dspace/* -mtime +90 -exec rm {} ;

Now Save (ctrl+o) and close (ctrl+x) 

The above-mentioned commands will take a backup of the database, file, and logs at 5:30 P.M. daily and after 90 days it will delete automatically old files at 05:00 P.M.

No comments

Powered by Blogger.