Solved

ubuntu incremental backup script

Posted on 2013-11-24
6
373 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now