I want to backup my Ubuntu system and I have two partitions to care: One is /, another is /home.
I'll likely want to backup /. This is not even that big so I can carry it on my SD card, while being responsive enough for making me want to have a image of it (that's why I'm trying to use rsync at this moment).
And about /home, it has many subdirectories that I do not care about much so I'll not likely include them, but I want to take care about files on there, such like .bash_history, .bashrc, .face, and so on.
So I want to exclude all subdirectories while including files in /home. How can I achieve that?
--exclude "*/" wasn't working. "/*/", "/**/", --include "*" --exclude */ doesn't show me what I want. at least it copied the source folder, without copying anything inside it.
4 Answers
Try this command:
rsync -a -f"- */" -f"+ *" /home/user/ destination/ man rsync
-f, --filter=RULE add a file-filtering RULE The rule to include all files* and exclude the dirs */
Another approach to use the regular copy cp
cp /home/usr/* /destination you can get rid of the errors about dirs using redirection
cp /home/usr/* /destination 2>/dev/null This will only copies the files inside your home without the directories
8If you want to solve this with --include and --exclude parameters, you should change the order of them: first exclude what you want, then include everything. I do it usually with this command:
rsync -vazhP path/to/source path/to/dest --exclude '*/*/' --include '*' By default, rsync does not copy directories. Perhaps you are using the -a flag. If this is the case, notice that according to the man page, -a is equivalent to -rlptgoD, so if you don't want to recurse, just use -lptgoD.
Try this:
rsync -r --exclude='*/' source/ destination/