rsync with link-dest and empty directories - linux

When using rsync with --link-dest, rsync does not copy empty directories from source to destination, a file has to change for that to happen.
Is there anyway to force it to create the empty directories?

You could run an additional rsync to create the empty directories:
rsync -av -f"+ */" -f"- *" <src> <dest>

Related

Rsync specific files and folders in linux

I want to rsync specific files in multiple subfolders
Example: Here my folder structure
home
home/shared/
home/shared/bav
home/shared/backups
home/shared/plugins
I want to rsync only "bav" files from this path. I am trying below command
rsync -av --list-only --include 'home/' --include 'home/shared/***' --include 'home/shared/bav' --exclude '*' -e $source:$target
But above command lists all files under "home" dir, I want only "bav" file

rsync files/folders from a list in an input file and exclude from an exclude file

I have two files with a list of folders. I want to sync the folders, with relative paths, to the destination excluding those from the exclude file.
$ cat include.txt
/home/user
/etc
/data/app
/boot
$ cat exclude.txt
/data/app/temp
/etc/aide
I have tried using --include-from and --files-from but can't seem to figure out it.
This seems to sync the folders, but not the files:
rsync -av --files-from=include.txt / /destination
Ultimately I want to sync to /destination and have the folder structure look like:
/destination/home/user
/destination/home/user/...
/destination/etc
/destination/etc/...
/destination/data/app
/destination/data/app/...
/destination/boot
/destination/boot/...
Just add -r and --exclude-from options and You should be good to go:
rsync -av -r --files-from=./include.txt --exclude-from=./exclude.txt / /destination/

Why does `rsync <...> /path/to/someDir /path/to/otherDir` leave me with `/path/to/otherDir/someDir`, not syncing files from `someDir` into `otherDir`?

Why is my rsync doing that? It's basically just making a copy of the someDir folder inside otherDir. If I run the command again after making changes in /path/to/someDir, rsync will sync all files from /path/to/someDir to /path/to/otherDir/someDir. How do I get all the files inside /path/to/someDir synced to /path/to/otherDir.
This is what the command looks like that I'm excuting:
rsync --stats --compress --recursive --times --perms --links --delete --exclude ".git" --exclude "wp-content/upload" --exclude "wp-content/uploads" --exclude "wp-content/gallery" /path/to/someDir /path/to/otherDir
rsync is one of the few commands that make a distinction between /your/path and /your/path/
When you don't use the trailing backslash you are referring to the directory, while when you use it you are referring to the contents of the directory.
Try
rsync --stats --compress --recursive --times --perms --links --delete --exclude ".git" --exclude "wp-content/upload" --exclude "wp-content/uploads" --exclude "wp-content/gallery" /path/to/someDir/ /path/to/otherDir
That extra trailing slash in /path/to/someDir/ will make the contents of it available in /path/to/otherDir.
BTW: Don't be tempted to use /path/to/someDir/* as was suggested, that will give you problems when you have many files and it won't copy files with names beginning with ..
The /path/to/someDir refers to the folder, someDir, not the files inside.
If you want instead to copy the files out of /path/to/someDir, try this:
rsync... /path/to/someDir/ /path/to/otherDir

Rsync how to include directories but not files?

I have a directory structure and files like this
data/
data/a.txt
data/folder/
data/folder/b.txt
data/folder/folder/
data/folder/folder/c.txt
...
a.txt, b.txt, and c.txt are large files that are computer-generated and renewed frequently. They should NOT be backuped -- but I want to backup the directory structure :
data/
data/folder/
data/folder/folder/
How can I do this with rsync and --exclude-from, without specifying every folder, but something like rsync -a data/* --exclude-from=exclude.rsync "" --onlyfoldersandnotfiles""?
Thanks for help !
rsync -a --include='*/' --exclude='*' source/ destination/
Basically, first include all directories, then exclude all files.
$ rsync -a -f"+ */" -f"- *" source/ destination/
"The two -f arguments mean, respectively, "copy all directories" and then "do not copy anything else"."
Further details: http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html
rsync -a -f"-! */" source/ destination/
Filter rule means "Exclude anything that's not a directory."
If you want to sync everything except one folder but you still want to keep the directory structure of that excluded folder, you should do the following:
$ rsync -a -f"+ /var/log/**/*/" -f"- /var/log/**/*" source/ destination/
See the exclude-list and the rsync command as an example.

On Linux, how do I recursively copy files while ignoring certain names?

I need to recursively copy a directory tree, ignoring any subdirectories named 'CVS'. Is there a simple way to do this?
rsync -av --exclude=CVS <src> <dst>
tar -cpf - --exclude=CVS directory | sh -c 'cd /wherever/it/goes && tar -xpf -'
Modify the right-hand tar's options to -xvpf if you'd like to see what's going on.
Why not approach it from a slightly different angle and check out the files from CVS using the export command.
This'll give you the directories without any of the CVS artifacts.

Resources