Could you please someone guide for the below incremental backup script, i have already written the script. I am facing an issue while looping the script.
Requirement i need : Consider a source folder contains A, B, C when i ran the script A, B, C will move to the destination folder. Again in source folder new files/directories added i.e. D,E when again if i ran the script now it should check for already present files. Here in our case A,B,C is already present in the destination. So only D,E have to move to the destination.
From the below code am able to backup , but how to make in loop Please guide
#!/bin/bash
####################################
#
# Backup IS server script script.
#
####################################
# What to backup.
Integrationserver="/home/ec2-user/source"
# Where to backup to.
dest="/home/ec2-user/destination"
# Create archive filename.
#date=$(date +%F)
IS=source
hostname=$(hostname -s)
#archive_file="$hostname-$IS-$date.tar.gz"
archive_file="$hostname-$IS.tar.gz"
# Print start status message.
echo "Backing up $Integrationserver to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar --exclude=/home/ec2-user/source/logs* --exclude=/home/ec2-user/source/TC* -zcf $dest/$archive_file $Integrationserver
# Print end status message.
echo
echo "Backup finished"
date
The below code is working fine with all the conditions and requirements , But not sure how to exclude the multiple directories.. please guide
#!/bin/bash
source=/home/ec2-user/source
dest=/home/ec2-user/destination
for file in $(find $source -printf "%P\n") ; do
if [ -a $dest/$file ] ; then
if [ $source/$file -nt $dest/$file ]; then
echo "Newer file detected, copying .."
cp -r $source/$file $dest/$file
else
echo "File $file exists, skipping"
fi
else
echo "$file is being copied over to $dest"
cp -r $source/$file $dest/$file
fi
done