Solved

ubuntu incremental backup script

Posted on 2013-11-24
6
378 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

828 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