LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-10-2013, 02:56 PM   #1
jms89
Member
 
Registered: Jan 2013
Posts: 41

Rep: Reputation: Disabled
rsync --delete question


Hi, I am using rsycn with the --delete command, but I want to prevent certain directories from being removed with this command, that are not directly part of the --exclude-from list.

Here's a schematic of what my two directory structures look like:

source disk directory: /foo /excluded_directories
target disk directory: /foo /remote_stuff

Here "/foo" respresents a group of directories which I am interested in syncing and deleting files from, and /remote_stuff are directories on the target disk which are not on the source disk, and which I want left alone.

If I just apply rsycn like --exclude-from "exlude list" --delete /source/ /target/ then the /remote_stuff directories will be deleted. I don't want this, how can I prevent it?

Thanks!
 
Old 02-10-2013, 03:20 PM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,183
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
It should not delete anything that is in the exclude list (as long as --delete-excluded is not used). Can you put these directories in the exclude list? If you want those directories to be "add enw files but do not delete existing files that do not exist in the source" then I think you need to do two runs of rsync. One run would focus (source and destination) on the subdirectory to be updated without delete, and one run on the whole tree with that subdirectory excluded.
 
Old 02-10-2013, 05:02 PM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,461
Blog Entries: 1

Rep: Reputation: 66
You have to build a small bash program around your rsync.
You have not to rsync /foo, but instead /foo/allowed_dir_1 /foo/allowed_dir_2, etc...
I did this with the help of the following code (it is not the entire code, it is just the section that matter for this discussion).
As you can see, the exclude list is a extend grep pattern format. I list the content of current source dir and exclude from this listing the folders I don't want to sync. Then, I run rsync for each allowed dir inside the for loop.

Code:
RSYNC="/usr/bin/rsync"
src="/home"
dst="homeusr@${host}::home"
flags="-az -Ap --delete"
exclude="lost+found|PrivateArea|Softwares|former-employees"
export RSYNC_PASSWORD="mySecretPassword"

cd ${src}

for dir in $(\ls -d | grep -Ev "${exclude}"); do
	if [ "$verbose" == "1" ]; then
		echo "running: nice -n 19 $RSYNC $flags --exclude "${exclude}" $dir $dst"
	fi
	nice -n 19 $RSYNC $flags $dir $dst
done
cheers,
 
Old 02-10-2013, 09:46 PM   #4
jms89
Member
 
Registered: Jan 2013
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by marozsas View Post
You have to build a small bash program around your rsync.
You have not to rsync /foo, but instead /foo/allowed_dir_1 /foo/allowed_dir_2, etc...
I did this with the help of the following code (it is not the entire code, it is just the section that matter for this discussion).
As you can see, the exclude list is a extend grep pattern format. I list the content of current source dir and exclude from this listing the folders I don't want to sync. Then, I run rsync for each allowed dir inside the for loop.

Code:
RSYNC="/usr/bin/rsync"
src="/home"
dst="homeusr@${host}::home"
flags="-az -Ap --delete"
exclude="lost+found|PrivateArea|Softwares|former-employees"
export RSYNC_PASSWORD="mySecretPassword"

cd ${src}

for dir in $(\ls -d | grep -Ev "${exclude}"); do
	if [ "$verbose" == "1" ]; then
		echo "running: nice -n 19 $RSYNC $flags --exclude "${exclude}" $dir $dst"
	fi
	nice -n 19 $RSYNC $flags $dir $dst
done
cheers,
Cool, this makes sense. I'm a little new to bash scripting so I don't understand all of the syntax, but I do understand what you're doing. Just curious, why the nice command though? I don't see why this is should be neccessary, does it speed things up for you?
 
Old 02-11-2013, 07:14 AM   #5
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,461
Blog Entries: 1

Rep: Reputation: 66
No, its is just the opposite. The nice makes the things slower, with a low priority.
The reason for this is this sync is done in a production machine, every 15min or so, and I don't want to impact other process with the sync.
Of course, if this is not an issue, you can safely omit the nice command so the line becomes just "$RSYNC $flags $dir $dst". After the shell substitutions it becomes something like this: "/usr/bin/rsync -az -Ap --delete allowed_dir_n homeusr@remotemachinename::home".

cheers,

Last edited by marozsas; 02-11-2013 at 07:17 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 --delete not working shea1roh Linux - Software 8 08-10-2015 11:08 PM
Rsync not working with include and delete. gregmcc Linux - Newbie 5 07-14-2012 02:15 AM
rsync doesn't seem to delete cooks44 Linux - Software 10 11-22-2007 12:57 AM
rsync newbie --delete -b noir911 Linux - General 1 11-23-2006 01:21 AM
rsync --delete question Red Squirrel Linux - Software 2 10-10-2005 10:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:35 PM.

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
Open Source Consulting | Domain Registration