After trying to take backup of modified files only(http://www.murga-linux.com/puppy/viewtopic.php?t=82975), I came up with two small scripts. Here I am sharing the scripts, please use it if you find it good. Please suggest improvements.
This script automatically remembers upto what date you have taken the backup.
Now it will start taking your backup since 01 Jan 2013. Then it remembers the date on which you have taken the backup. Then onwards simply run this script, it will take backup of files modified since last backup!
backup.sh
restore.sh#!/bin/sh
last_N_days=30
exception1="dont_backup.txt"
src_dir=""
dst_dir=""
backup_log=""
usage()
{
echo Usage: backup.sh src-dir dst-path
echo Example: backup.sh /mnt/sda5 /mnt/sdb1
echo Modify Pattern for \"files to be excluded from back-up\" in backup.sh file.
}
echo hello
if [ $# != 2 ]
then
usage
else
backup_log=`pwd`
backup_log=$backup_log/backup.log
echo > $backup_log
echo check $backup_log for files excluded from backup
this_script=`realpath "$0"`
src_dir=$1
dst_dir=$2
echo you have given $1 as source directory
echo you have given $2 as destination directory
if [ ! -d $src_dir ]
then
echo source directory $src_dir does not exist
exit
fi
if [ ! -d $dst_dir ]
then
echo destination directory $dst_dir does not exist
exit
fi
cd $src_dir
src_dir=`pwd`
cd - > /dev/null
cd $dst_dir
dst_dir=`pwd`
cd - > /dev/null
echo complete path for source directory is $src_dir
echo complete path for destination directory is $dst_dir
src_dir_to_copy=`echo $src_dir | awk -F/ '{print $NF}'`
echo backup will copy complete $src_dir_to_copy/ directory to $dst_dir
time_stamp=`cat $this_script | tail -1 | awk '{print $2}'`
if [ "$time_stamp" = "" ]
then
echo Run it now!
echo \#Upto `date +%Y%m%d%H%M` >> $this_script
exit
else
echo taking backup from $time_stamp
fi
touch -t $time_stamp $this_script
cd `dirname "$src_dir"`
#find $src_dir_to_copy -type f -ctime -$last_N_days | while read file_name;
find $src_dir_to_copy -type f -cnewer $this_script | while read file_name;
do
file_excluded=`echo $file_name | grep $exception1`
if [ $file_excluded ]
then
echo $file_name >> $backup_log
else
new_path_for_file=$dst_dir/$file_name
new_dir_for_file=`dirname "$new_path_for_file"`
echo directory $new_dir_for_file will be created if does not exist
mkdir -p "$new_dir_for_file"
echo $file_name file will be copied in to it
cp "$file_name" "$new_dir_for_file"
fi
done
cd - > /dev/null
echo ========Files excluded from backup========
cat ./backup.log
echo ========Files excluded from backup========
(echo "g/^#Upto 201/d"; echo 'wq') | ex -s $this_script
echo \#Upto `date +%Y%m%d%H%M` >> $this_script
fi
echo done
#=====keep_this_line=====
#Upto 201301010000
Sincerely,#!/bin/sh
src_dir=""
dst_dir=""
usage()
{
echo Usage: restore.sh src-dir dst-path
echo Example: restore.sh /mnt/sdb1/sda5 /mnt/sda6
}
echo hello
if [ $# != 2 ]
then
usage
else
src_dir=$1
dst_dir=$2
echo you have given $1 as source directory
echo you have given $2 as destination directory
if [ ! -d $src_dir ]
then
echo source directory $src_dir does not exist
exit
fi
if [ ! -d $dst_dir ]
then
echo destination directory $dst_dir does not exist
exit
fi
cd $src_dir
src_dir=`pwd`
cd - > /dev/null
cd $dst_dir
dst_dir=`pwd`
cd - > /dev/null
echo complete path for source directory is $src_dir
echo complete path for destination directory is $dst_dir
src_dir_to_copy=`echo $src_dir | awk -F/ '{print $NF}'`
echo restore will copy complete $src_dir_to_copy/ directory to $dst_dir
echo directory "$dst_dir/$src_dir_to_copy" will be created if does not exist
mkdir -p "$dst_dir/$src_dir_to_copy"
cp -v -r $src_dir/* $dst_dir/$src_dir_to_copy
fi
echo done
Srinivas Nayak