Shell Script to take backup of Application

Script to take the backup on daily basis via cron job

So first we will create a file "backup.sh" and taking backup of html folder 
vim /root/backup.sh        (Paste this content in the file)                     

#/bin/bash
## Author: Atul
## Description: This script is used to take backup  

DATE=$(date +%d-%b-%Y-%H-%M-%S)
DESDIR=”/backup/”
FILENAME=html-$DATE.zip

echo “Create Zip file of HTML folder” 
cd /var/www/  && zip -r $DESDIR/$FILENAME html  
cd /backup/

echo ” remove backup older than 4 days”
rm -rf $(ls -1t | grep html |tail -n +5)

Now, We are going to create a cron job for backup

for example, we are taking backup daily at 2:00 AM so now run this command;
crontab -e
After this command, you will see an open file and define the values like:

* 2 * * * /root/backup.sh
## we are running backup.sh script at 2:00 AM on daily basis

 

Check out : How to migrate gitlab from one server to another on CentOS7

Leave a Reply

Your email address will not be published. Required fields are marked *