I am trying to backup some of the essential folders in the / in my ubuntu system. I am using
sudo rsync -aAXv --delete --include="/etc" --include="/home" --include="/usr/local" // /home/$USER/Desktop/bkup/
This command should only copy /etc, /home, /usr/local dirs and leave the rest of the files. But, when I run this command this copies every dir and every file in the / dir.
I am not sure what wrong I am doing here.
Includes without any excludes are meaningless.
--exclude='*' would exclude everything not explicitly included, from every subfolder, even the included ones.
--exclude='*/' would exclude every directory not explicitly included, but allow copying files within included directories (and the root).
--exclude='/*' would exclude all root directories and files not explicitly included, but allow all directories and files within included directories. You probably want this one.
You should add your exclude rule after your include rules. The rule is that, for each directory and file, it's the first matching include/exclude rule that matters, and the default (when no rule matches) is to include.
By "root" I mean the root of the copied directory, not the root of the whole file system.
P.S. Your command also has the destination directory inside the source directory; you probably want an exclude rule for that!
Related
I would like to write a .prettierignore file to target the files in a single directory, which is nested one level down from the root of the project. I figure the most elegant way to accomplish this is to use a negated pattern to ignore everything but the target directory.
So, I currently have this:
# Ignore all
/*
# but for /views
!src/views/
Running the npx prettier --write . command with that pattern (or similar variations) appears to match no files, and no files change. However, if I run the command without/views in the pattern, i.e. just !src, then prettier formats everything in the src directory, including all the files in /views.
What am I missing that I can't successfully target only the nested /views directory?
After some more searching, I found this solution, which accomplishes the outcome I was seeking, though, I don't quite understand how it works.
#ignore all
/*
#but don't ignore files or directories at root called src
!/src
#ignore everything in src dir?
/src/*
#but don't ignore views dir in src?
!/src/views
Why would that be necessary compared to just src/views?
I have the following structure:
/source/link1/->/dir1
/source/link2/->/dir2
/source/link1/file2
/source/link1/link11->/dir2/file21
link=symbolic link, file=real file.
At the target (remote) directory links in the "root" of source folder should be copied as directories, and links under /source/link1, /source/link2 folders should not be copied, or they should be copied only as links (to avoid duplicate structure). Target structure is the following:
/target/link1 - directory
/target/link2 - directory
/target/link1/link11->/target/link2/file21
/target/link1/file2
How to maintain that with rsync?
It is needed for the daily sync - every day target and source folder should be synced, and rsync should be used with --delete command.
Rsync has a range of options for dealing with links (from the man page):
-l, --links copy symlinks as symlinks
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the tree
--munge-links munge symlinks to make them safer
-k, --copy-dirlinks transform symlink to dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
If it so happens that the top-level links are "unsafe" and the other links are all "safe", then --copy-unsafe-links will Just Work, for you.
Otherwise, I'd recommend that you use a loop to sync the top-level directories one at a time:
rsync -a --delete /source/link1/ /target/link1/
Note that -a implies --links, so any links inside the directories will be copied as links, verbatim. The top-level link1 will be treated as a directory if you use the trailing / to dereference it (i.e. it's outside the tree rsync is scanning).
I'm trying to change the permissions of a folder. I want to make a folder, and everything in it restricted to me only; other users can't view it.
The folder, though, contains hundreds of other files in it. Is there a way in Terminal to change the permissions a folder and everything in it? I know this can be accomplished with "Get info" but there's simply too much files inside that folder to manually do that with every file.
I'm running on OS X Mavericks 10.9.5.
Help would be greatly appreciated!
of course there is a way.
You should set the ownership to your user and remove at least the executable flag for the folder. No one will be able to enter the folder via the cd command or the finder, etc.
First change directory to the location where the desired folder is located (its parent folder).
cd path/to/parent/folder
then remove the executable flag for its group (g) and all others (o)
chmod go-x folder
If you also want to make its contents invisible for actions like
ls folder/
then you have to remove the readable flag also.
chmod go-r folder
#micebrain: And there is no need for changing the permissions recursively for all folders and files inside the folder, because you can control the access of opening a folder.
BTW the executable bit (x) - if set - makes files executable and folders openable...
According to Apache manual, the Include directive is recursive when a directory path is used. But is it recursive when using a wildcard path?
Include "/usr/local/apache/conf/userdata/std/2/username/domain.com/*.conf"
I checked it and it is not recursive.
As Joyce already said, I can confirm by testing it myself that it is not recursive.
Include uses fnmatch as wildcard engine, which doesn't match a slash by default, unless the FNM_PATHNAME flag is set, so a * doesn't match / so domain.com/*.conf will not look in sub-directories.
However, since httpd 2.3.6 it is possible to also use the wildcard for sub-directories.
Examples
Include /usr/local/apache2/conf.d/ssl.conf
This matches only a specific file.
Include /usr/local/apache2/conf.d
If conf.d is a file, it matches only this file. If conf.d is a directory, all files will be matched recursively, including files in sub-directories and non-conf files (which causes an error).
Include /usr/local/apache2/conf.d/*.conf
This will only match the files with a .conf suffix, directly located in the conf.d directory. Files in sub-directories aren't matches.
Include /usr/local/apache2/conf.d/*/*.conf
This will only match the files with a .conf suffix, directly located in sub-directories of the conf.d directory, but it will NOT match files directly located in the conf.d directory.
So for example, if you need to match all .conf files directly located in conf.d and in first level of sub-directories and second level of sub-directories, you can use this:
Include /usr/local/apache2/conf.d/*.conf
Include /usr/local/apache2/conf.d/*/*.conf
Include /usr/local/apache2/conf.d/*/*/*.conf
If you only have valid configuration files in conf.d and want to match every level of subdirectories, then you can use:
Include /usr/local/apache2/conf.d
Instead of using wildcard, you should use a directory.
It has been supported since as early as 1.3 https://httpd.apache.org/docs/1.3/mod/core.html#include
New in Apache 1.3.13 is the feature that if Include points to a directory, rather than a file, Apache will read all files in that directory, and any subdirectory, and parse those as configuration files.
I can't rely on the umask since my machine does not use umask to set permissions. Is there a way to specify that all sub-directories (and their sub-directories etc) of some root directory all have a certain permission, and similarly, that all sub-files of the same root directory have another type of permission in the %files section of the spec file.
If not, I'll have to run some external bash scrip to get the spec file syntax for each individual file, and copy that output to the %files section of the spec file, which will be highly tedious.
If you look at the various references online, %defattr() takes a lesser-known fourth parameter for directories.