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

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

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/

rsync with link-dest and empty directories

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>

FreeBSD copy directories with skip

I need to copy folders by this command:
cp -R /usr/www/data/www.domaun.com/WWW/ /usr/www/data/new.domain.com/
But skip directories:
audio
b
f
img
tmp
and also skip files larger than 3 MB.
Thank you !
You could use rsync, e.g.
rsync -a --max-size=3M \
/usr/www/data/www.domain.com/WWW/ /usr/www/data/new.domain.com/ \
--exclude audio/ --exclude b/ --exclude f/ --exclude img/ --exclude tmp/

Excluding directory when creating a .tar.gz file

I have a /public_html/ folder, in that folder there's a /tmp/ folder that has like 70gb of files I don't really need.
Now I am trying to create a .tar.gz of /public_html/ excluding /tmp/
This is the command I ran:
tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp/"
The tar is still being created, and by doing an ls -sh I can see that MyBackup.tar.gz already has about 30gb, and I know for sure that /public_html/ without /tmp/ doesn't have more than 1GB of files.
What did I do wrong?
Try removing the last / at the end of the directory path to exclude
tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp"
Try moving the --exclude to before the include.
tar -pczf MyBackup.tar.gz --exclude "/home/user/public_html/tmp/" /home/user/public_html/
The correct command for exclude directory from compression is :
tar --exclude='./folder' --exclude='./upload/folder2' -zcvf backup.tar.gz backup/
Make sure to put --exclude before the source and destination items.
and you can check the contents of the tar.gz file without unzipping :
tar -tf backup.tar.gz
Yes, remove the trailing / and (at least in ubuntu 11.04) all the paths given must be relative or full path. You can't mix absolute and relative paths in the same command.
sudo tar -czvf 2011.10.24.tar.gz ./start-directory --exclude "home/user/start-directory/logs"
will not exclude logs directory but
sudo tar -czvf 2011.10.24.tar.gz ./start-directory --exclude "./start-directory/logs"
will work
You can also exclude more than one using only one --exclude. Like this example:
tar -pczf MyBackup.tar.gz --exclude={"/home/user/public_html/tmp","/home/user/public_html/data"} /home/user/public_html/
In --exclude= you must finish the directory name without / and must in between MyBackup.tar.gz and /home/user/public_html/
The syntax is:
tar <OPTIONS> <TARBALL_WILL_CREATE> <ARGS> <PATH_TO_COMPRESS>
The accepted answer did not work for me, running unxutils tar on windows10. Instead, I had to put the files/dirs to archive as the last parameter, like this:
tar -pczf MyBackup.tar.gz --exclude "/home/user/public_html/tmp/" /home/user/public_html/
Then it worked.
This worked for me:
tar -zcvf target.tar.gz target/ --exclude="target/backups" --exclude="target/cache"
tar -pczf <target_file.tar.gz> --exclude /path/to/exclude --exclude /another/path/to/exclude/* /path/to/include/ /another/path/to/include/*
Tested in Ubuntu 19.10.
The = after exclude is optional. You can use = instead of space after keyword exclude if you like.
Parameter exclude must be placed before the source.
The difference between use folder name (like the 1st) or the * (like the 2nd) is: the 2nd one will include an empty folder in package but the 1st will not.
Try this
tar -pczvf advancedarts.tar.gz /home/user/public_html/ --exclude /home/user/public_html/tmp
The exclude option needs to include the = sign and " are not required.
--exclude=/home/user/public_html/tmp

Resources