Backup with auto delete old files


Auto deletion of old backup files helps save cloud space.

Here is a shell script to schedule the backup with a time stamp. It keeps three days of backup and deletes previous files to save space. This method is convenient for working with cloud storage with limited space (e.g. Dropbox). 
Follow the instructions below to schedule the backup.

Download the shell script

Copy the shell script to the home folder. Open the shell script and make changes to the Koha database, username, password and location of the backup. The timestamp of the database also appears on the backup file name. Give the number of days the backup keeps.

Move the shell script to /usr/local/bin

sudo cp backup.sh /usr/local/bin

Give the necessary permission to the shell script,

cd /usr/local/bin
sudo chmod +x backup.sh

Create the cronjob entry of the backup. Apply the following command on the terminal.

export EDITOR=mousepad
crontab -e

Copy the below lines to the bottom part of the crontab file.

#Koha backup
10 20 * * * /usr/local/bin/backup.sh

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

No comments:

Post a Comment