Backup shell script

By | June 14, 2019

One of the best and easy ways to backup a system is using a shell script, Using script we can take backup of directories and files or can move one location to otherĀ 

#!/bin/bash
#Purpose = Backup of Important Data
#Version 1.0
#START
# This Command will add date in Backup File Name.
TIME=`date +%b-%d-%y` 
# Here i define Backup file name format.
FILENAME=/var/www/html//-$TIME.tar.gz 
# Location of Important Data Directory (Source of backup).       
SRCDIR=/home//          
File=filename.txt
tar -cpvzf $FILENAME -P $SRCDIR > $File
status=$?
if test $status -eq 0
then
 echo "sucess"
else
  echo "failed need to check"
fi
size=$(du -sh $FILENAME)
line=$(wc -l $File)
echo Size of the tar is $size
echo Total verbose lines is $line
#END

 

I am saving this file as with name “backupscript.sh” location
“/home/”

The backup script is set up a cron
Cron: We can automate execute script or command.

45 23 * * 6 sh /home//backupscript.sh

Will run this scriot 23:45 ( 11:45 PM ) every Saturday and we will get backup

Syntax of corn

# * * * * * command to execute


Leave a Reply

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