Problem:Trying to copy the entire content of one directory to another which includes hidden files/directories and symlinks.This is fairly straightforward cp -a ${src} ${dst}It works as expected on my local VM but it doesn't work properly on my VPS (hostgator). It fails to copy the symlinks if the link target comes later in the directory listing.Considering that the original link targets work, are device local and I'm copying on the same device, what is the best way to make sure that the entire directory structure is copied exactly?It took me quite a while but I figured out that all I actually need to do is run the copy command twice and the second pass adds the missing links. Is there a better way than this?Working but Hack-ish Solution:src=.default/.;dst=tld.domain/;cp -a ${src} ${dst};cp -a ${src} ${dst};I shouldn't need to double up the command to ensure that everything copied correctly.I tried tar as well, same issue. I didn't try rsync but both seem like an overkill solution for something that should be a pretty trivial thing.Scenario:For additional perspective in case it matters or I haven't be clear.I have created a template directory structure for website domains. After creating a new sub-domain on my web-host, I copy the template over to the sub-domain's document root.This is my subdomain and template (.default/) directory structure:sites/    .default/        .htaccess        .www -> production/        production/    tld.domain.x/    tld.domain.y/    tld.domain.z/So I create a new subdomain and then populate it's document root with the contents of the template directory. The issue here is that .www/ is a symlink to production/ but cp et al create everything in sorted order so it tries to create .www/ before creating production/ and consequently fails.My web-host is a HostGator VPS running CentOS6I can drill the issue down to some restriction on creating symlinks. My guess is that the VPS doesn't allow symlinks to external sources which would normally behave the same as an invalid link target. IE unknown source.Where neither names exist, calling on my VPS:ln -s foo barOutputs:ln: creating symbolic link `bar': Permission deniedIf I create foo/ first then link, it works as expected.df -T . shows that the filesystem type is virtfs.
cp -a fails to copy symlinks on virtfs
symlink;file copy;virtfs