Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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
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?
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".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.