Solved

ubuntu incremental backup script

Posted on 2013-11-24
6
376 Views
Last Modified: 2013-11-29
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
0
Comment
Question by:xeroxzerox
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Assisted Solution

by:alexziv
alexziv earned 150 total points
ID: 39673876
0
 
LVL 6

Author Comment

by:xeroxzerox
ID: 39673883
i've already done by webguru script but it's not working.
0
 
LVL 1

Expert Comment

by:alexziv
ID: 39673895
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 19

Expert Comment

by:xterm
ID: 39676167
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

0
 
LVL 6

Author Comment

by:xeroxzerox
ID: 39676659
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
0
 
LVL 19

Accepted Solution

by:
xterm earned 350 total points
ID: 39677760
Here you go, modified to use tar instead of cp so it will create the directories in the structure you requested:

#!/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 -p $CHG
        fi
        (tar cpf - $CHANGE ) | (cd $CHG && tar xvfp -)
done

rm -f $OUTPUT

Open in new window

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question