LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2013, 06:46 AM   #1
mokapoor
LQ Newbie
 
Registered: Oct 2013
Posts: 4

Rep: Reputation: Disabled
Configure Rsync script for backup


hi,

I need a script for take backup only modified files in directory.

Scenario is:

Test
|-- hr
| `--user1
| `--1.txt
|-- it
| `--it1
| `--2.txt
|-- pa
| `--pa1
| `--3.txt

How to take backup by rsync only modified file in other system.
 
Old 11-08-2013, 08:11 AM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,178
Blog Entries: 10

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
Code:
rsync -avz /path/to/Test /path/to/storage --delete
I use the --delete option in my own backup/to/USB script to keep things consistent.
If you don't use --delete then any files deleted under /path/to/Test (the source) will remain in the /path/to/storage (destination)
on subsequent runs of rsync.

What "other system" is that reference to?
some examples - http://www.thegeekstuff.com/2010/09/...mand-examples/
the basics - http://aplawrence.com/Basics/rsync.html
 
Old 11-08-2013, 11:11 AM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
yeah i use the following arugments in my rsync backup script:

Code:
rsync -aviS source destination
man rsync for details on those options.
 
Old 11-08-2013, 10:54 PM   #4
mokapoor
LQ Newbie
 
Registered: Oct 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for response.

I've ran the script but output not showing in another folder...

i've ran following script but it's not creating date folder in output place.
( script will be run daily basis on system so i need it create date folder in output dir and take backup only updated file)

#rsync -aviS --backup-dir=`date +%d-%m-%Y` /test 192.168.0.230:/mnt/abc
 
Old 11-10-2013, 01:22 AM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by mokapoor View Post
Thanks for response.

I've ran the script but output not showing in another folder...

i've ran following script but it's not creating date folder in output place.
( script will be run daily basis on system so i need it create date folder in output dir and take backup only updated file)

#rsync -aviS --backup-dir=`date +%d-%m-%Y` /test 192.168.0.230:/mnt/abc
you still need to provide the full path.

you are better off if you wish to create a folder to create it BEFORE running the rsync command in your script with something like this:

Code:
### Check for a logs directory, if not found create one
[ ! -d "${HOMEDIR}/logs" ] && mkdir -p ${HOMEDIR}/logs >> /dev/null 2>&1
now that is how i create and verify that my log folder is were i want it. if its not there then it will make it. you can do the same thing with date, just create your variables and substitute in what needs be adjusting.
 
Old 11-11-2013, 10:15 AM   #6
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 306

Rep: Reputation: 121Reputation: 121
Quote:
Originally Posted by mokapoor View Post
i've ran following script but it's not creating date folder in output place.
Code:
#rsync -aviS --backup-dir=`date +%d-%m-%Y` /test 192.168.0.230:/mnt/abc
That is not the way --backup-dir works. It does not specify the destination directory (which I think you are calling your "backup"). It specifies a directory to save files that would be changed or deleted by rsync on the destination directory. I'll write more on that later.

Edit: Sorry, I mis-read your rsync command (didn't see a space), so what I wrote below (now red) is incorrect:

If you wish to transfer files from /test 192.168.0.230:/mnt/abc to `date +%d-%m-%Y`, the appropriate command might be:
Code:
rsync -aviS /test 192.168.0.230:/mnt/abc `date +%d-%m-%Y`

This is what I should have written:

Your command looks okay to transfer files from /test to 192.168.0.230:/mnt/abc, but the --backup-dir switch will not do anything unless you also use --backup, like so:
Code:
rsync -aviS --backup --backup-dir=`date +%d-%m-%Y` /test 192.168.0.230:/mnt/abc

Last edited by Beryllos; 11-11-2013 at 09:42 PM. Reason: correcting an error due to my incorrect reading of OP's command line
 
Old 11-11-2013, 11:36 AM   #7
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 306

Rep: Reputation: 121Reputation: 121
Now I will show an example of how --backup-dir works. By the way, all this is in the rsync manual. If the manual is not sufficiently clear, you can experiment with the rsync command on a small directory to figure out how it works.

I have a directory called "a" which I intend to transfer to a directory called "b".

Also I will use the --delete switch, so that files deleted from the source directory will be deleted by rsync on the destination directory. Some people call this mirroring; after running rsync with --delete, the destination directory will reflect all changes to the source directory, including any deletions that may have occurred since the last rsync.
Code:
$ ls
a
$ ls a
x  y  z
$ rsync -aviS --delete a/ b/
sending incremental file list
created directory b
cd+++++++++ ./
>f+++++++++ x
>f+++++++++ y
>f+++++++++ z

sent 233 bytes  received 72 bytes  610.00 bytes/sec
total size is 28  speedup is 0.09
$ ls
a  b
$ ls b
x  y  z
$
Now I will delete one file and repeat the rsync command:
Code:
$ rm a/x
$ rsync -aviS --delete a/ b/
sending incremental file list
.d..t...... ./
*deleting   x

sent 66 bytes  received 15 bytes  162.00 bytes/sec
total size is 23  speedup is 0.28
$ ls b
y  z
$
You see that it deleted b/x. Let's delete another file and use the --backup and --backup-dir options. Please note, --backup-dir without --backup does nothing.
Code:
$ rm a/y
$ rsync -aviS --delete --backup --backup-dir="c" a/ b/
sending incremental file list
.d..t...... ./
*deleting   y

sent 56 bytes  received 15 bytes  142.00 bytes/sec
total size is 11  speedup is 0.15
$ ls b
c  z
$ ls b/c
y
$
Now you see that the file b/y has been moved to the backup directory b/c.

Last edited by Beryllos; 11-13-2013 at 03:09 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync backup script help henryyy Linux - Newbie 7 03-05-2013 03:31 PM
LXer: Rsync Backup for Windows, Linux Knoppix, and Other Smart Technologies in Handy Backup by Novos LXer Syndicated Linux News 0 12-24-2011 12:43 PM
rsync in a backup script doesn't delete-after j1alu Programming 6 10-07-2010 12:48 AM
LXer: Backup with rsync and rsync.net LXer Syndicated Linux News 0 09-14-2010 05:20 PM


All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration