Step 1 : create a file /path/to/backupfilelist.txt which contains the files & directory which you want to take bacup
Step 2 : Write a script backup_files_and_directory.sh
#!/bin/sh
#Script for take a backup of list of files and directory in one compress file
#file format which contains backup files & directory
FILENAME="`date +%d-%m-%Y`.tar.gz"
#This file contains the files & directory which we are going to take backup
BACKUPFILELIST="/path/to/backupfilelist.txt"
#Directory where backup kept
BACKUPDIRECTORY="/root/filebackup"
TAR=`which tar`
#create backup directory if not exist
if [ ! -d $BACKUPDIRECTORY ]; then
mkdir -p /root/filebackup
fi
#check backupfilelist.txt is available or not
if [ -f $BACKUPFILELIST ]; then
BACKUPFILE=`cat $BACKUPFILELIST | grep -E -v "^#"`
else
echo "File not Exist...Please create Backup file first"
exit 1
fi
#check for the backupfilelist.txt null or not
if [ $BACKUPFILELIST = "" ]; then
echo "Backup file list is empty..Please add some files or directory to take backup"
exit 2
fi
#take a bakcup
$TAR -zcvf $BACKUPDIRECTORY/$FILENAME $BACKUPFILE > /dev/null
Step 3 : make script executable
#chmod +x backup_file_and_directory.sh
Step 4 : execute file
#./backup_file_and_directory.sh
No comments:
Post a Comment