Closed Chaitanyarjoshi closed 3 years ago
#!/bin/bash
#####
# Is the file system there? Then quit.
if [ ! -d /data/backup/LT/ ] ; then
exit;
fi
#####
#Sourcing configuration file
source /home/rsyncbkup/bkup/conf/bkup.cfg
#The `hostname` directory should have been created on the remote server as a pre-requisite
{
# Get last modified file from source directory.
BACKUP_FILENAME=$(ls -tr $SRC_DIR_LT | tail -n 1)
echo "Checking to see if a directory with today's date exists ....."
if ssh -q $BKUP@$BKUPSERVER "test -d $DEST_DIR_LT/backup_$DATE "
then
echo "Directory $DEST_DIR_LT/backup_$DATE exists
The files will be transferred shortly"
rsync -azv -e ssh $SRC_DIR_LT/$BACKUP_FILENAME $BKUP@$BKUPSERVER:$DEST_DIR_LT/backup_$DATE/
exit 0
else
echo "Directory $DEST_DIR_LT/backup_$DATE does not exist.
It will be created and the files will be transferred"
fi
rsync -azv --rsync-path="mkdir $DEST_DIR_LT/backup_$DATE && rsync" -e ssh $SRC_DIR_LT/$BACKUP_FILENAME $BKUP@$BKUPSERVER:$DEST_DIR_LT/backup_$DATE/
if [ $? -eq 0 ]
then
echo "File transfer successful"
else
echo "File transfer FAILED on $DATE$TIME"
exit 1
fi
} > $LOGDIR/stlog_$TIME.log 2>&1
~
I have a backup script in place which uses rsync to backup the files and create a folder with the current date stamp on the destination server. Now every-time this script is run it copies all the files from the source directory to the destination folder. Now I want to add a logic where it only picks up the files from the same day, i.e. every-time the script is run I want it to copy the files created on that particular day to be copied over to the destination folder which gets created with the current date stamp instead of copying all the files from the source directory. bkupscriptconfig.txt bkupscript.txt