Question

Every-time I copy recursively I always end up with httpdocs folder instead of the files within in public_html.

For example I might run something like:

cp -rpf /var/www/vhosts/website/httpdocs /var/www/vhosts/anotherwebsite/httpdocs

I always end up with /var/www/vhosts/anotherwebsite/httpdocs/httpdocs when all I am trying to do is move a website from one user to another.

Was it helpful?

Solution

When you just want to "push" your local website without getting offline long, you can use a temporary dir.

TODAY=$(date +%y%m%d)
NEWCODE=/var/www/vhosts/anotherwebsite/docs_${TODAY}
OLDCODE=/var/www/vhosts/anotherwebsite/docs_old
rm -rf ${NEWCODE}
cp -rpf /var/www/vhosts/website/httpdocs ${NEWCODE} || exit 1
# some checks ?
cd /var/www/vhosts/anotherwebsite/ || exit 1
mv httpdocs ${OLDCODE} || exit 1
mv ${NEWCODE} httpdocs

Between the moves you will be unavailable. When that is a problem, you might want to make a work_in_progress.html file, rename that file to httpdocs/index.html, remove all other files and copy the new files after this (the correct index.html file as the last one). But this seems to fancy, stick with the short hickup in the solution above.

OTHER TIPS

Wat do you want when a file exists under aontherwebsite and not in the source website? I think you want anotherwebsite to be an exact copy, so make sure the old files are removed first.

rm -r /var/www/vhosts/anotherwebsite/httpdoc
cp -rpf /var/www/vhosts/website/httpdocs /var/www/vhosts/anotherwebsite/httpdoc

Edit: anotherwebsite should stay available. The general trick is using tar:

tar cf - * | ( cd /target; tar xf -)

In your case:

TARGET=/var/www/vhosts/anotherwebsite/httpdoc
cd /var/www/vhosts/website/httpdocs || exit 1
mkdir -p ${TARGET}
[ -d ${TARGET} ] || exit 1
tar cf - * | ( cd ${TARGET}; tar xf -)

I added "|| exit 1" to be sure you do not copy from the wrong dir and ${TARGET} is a dir. You still have 3 challenges: 1) How do you delete files you do not use anymore (yesterday_special_action.html) 2) should you copy images first, for customers opening new pages before the images are copied 3) what website do you have if the copy/tar fails after copying a part (disk full)

I will post a new answer for solving these challenges.

You need to tell copy to treat the destination directory as a file instead of as a directory (into which to copy the folder that you've listed as your source). Which means you need the -T option.

Alternatively you could use a source of /var/www/vhosts/website/httpdocs/* if that glob captures all the files you actually care about. That should work too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top