Link to home
Start Free TrialLog in
Avatar of Zerox Hoop
Zerox HoopFlag for India

asked on

ubuntu incremental backup script

Hi Experts.

Need a shell script for incremental backup.
when we run script first time it take full backup.
next time we changes in source file.
And again run script that time it tale backup only modified file in new date folder.

Thanks & Regards,
Xeroxzerox
SOLUTION
Avatar of alexziv
alexziv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zerox Hoop

ASKER

i've already done by webguru script but it's not working.
Here's a simple script that uses the "itemize" function of rsync to tell you which files have changed, and put those in a seperate dated folder, which is what I think you were requesting:

#!/bin/sh

STAMP=`date +%Y%m%d-%H%M%S`

SRC="sourcefolder"
DST="destfolder"
CHG="$DST/$STAMP"
OUTPUT="rsync.out"

rsync -avi $SRC $DST > $OUTPUT

for CHANGE in `grep ^\>f $OUTPUT | awk '{print $2}'`;
do
        if [ ! -d $CHG ]; then
                mkdir $CHG
        fi
        cp -v $CHANGE $CHG
done

rm -f $OUTPUT

Open in new window

First time when i've ran script i found below output

|-- 20131201-192343
|   |-- 1.txt
|   |-- 2.txt
|   |-- 3.txt
|   |-- 4.txt
|   `-- 5.txt
|-- xerox
|   |-- hr
|   |   `-- user1
|   |       `-- 5.txt
|   |-- IT
|   |   |-- user2
|   |   |   `-- 3.txt
|   |   `-- user3
|   |       |-- 1.txt
|   |       `-- 2.txt
|   `-- pa
|       `-- user4
|           `-- 4.txt
`-- rsync.out
that time it make a two backup
next time i've modified in hr>user1>5.txt and run the script.Now output is
|-- 20131201-192343
|   |-- 1.txt
|   |-- 2.txt
|   |-- 3.txt
|   |-- 4.txt
|   `-- 5.txt
|-- 20131201-192554
|   `-- 5.txt
|-- xerox
|   |-- HR
|   |   `-- user1
|   |       `-- 5.txt
|   |-- it
|   |   |-- user2
|   |   |   `-- 3.txt
|   |   `-- user3
|   |       |-- 1.txt
|   |       `-- 2.txt
|   `-- pa
|       `-- user4
|           `-- 4.txt
`-- rsync.out

But now i want a output like that.
|-- 20131201-192554
|   |-- HR
|   |   `-- user1
|   |       `-- 5.txt
|-- xerox
|   |-- HR
|   |   `-- user1
|   |       `-- 5.txt
|   |-- it
|   |   |-- user2
|   |   |   `-- 3.txt
|   |   `-- user3
|   |       |-- 1.txt
|   |       `-- 2.txt
|   `-- pa
|       `-- user4
|           `-- 4.txt
`-- rsync.out
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial