3

I'm copying files from a git repository into a virtualhost folder, although none of the following commands do overwrite existing files:

sudo cp -R /home/git/repo /var/www/website
sudo cp -R -f /home/git/repo /var/www/website

How can I make sure the cp command overwrites existing files?


Edit: Quick test, copying files from the webdir to the repo does overwrite files, so apparently something (www-data?) is locking the files in the webdir. The mount output:

~$ mount | column -t
sysfs       on  /sys                             type  sysfs       (rw,nosuid,nodev,noexec,relatime)
proc        on  /proc                            type  proc        (rw,nosuid,nodev,noexec,relatime)
udev        on  /dev                             type  devtmpfs    (rw,nosuid,relatime,size=1005964k,nr_inodes=251491,mode=755)
devpts      on  /dev/pts                         type  devpts      (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs       on  /run                             type  tmpfs       (rw,nosuid,noexec,relatime,size=204840k,mode=755)
/dev/vda1   on  /                                type  ext4        (rw,relatime,errors=remount-ro,data=ordered)
securityfs  on  /sys/kernel/security             type  securityfs  (rw,nosuid,nodev,noexec,relatime)
tmpfs       on  /dev/shm                         type  tmpfs       (rw,nosuid,nodev)
tmpfs       on  /run/lock                        type  tmpfs       (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs       on  /sys/fs/cgroup                   type  tmpfs       (ro,nosuid,nodev,noexec,mode=755)
cgroup      on  /sys/fs/cgroup/systemd           type  cgroup      (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore      on  /sys/fs/pstore                   type  pstore      (rw,nosuid,nodev,noexec,relatime)
cgroup      on  /sys/fs/cgroup/hugetlb           type  cgroup      (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup      on  /sys/fs/cgroup/freezer           type  cgroup      (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup      on  /sys/fs/cgroup/cpu,cpuacct       type  cgroup      (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup      on  /sys/fs/cgroup/memory            type  cgroup      (rw,nosuid,nodev,noexec,relatime,memory)
cgroup      on  /sys/fs/cgroup/devices           type  cgroup      (rw,nosuid,nodev,noexec,relatime,devices)
cgroup      on  /sys/fs/cgroup/net_cls,net_prio  type  cgroup      (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup      on  /sys/fs/cgroup/pids              type  cgroup      (rw,nosuid,nodev,noexec,relatime,pids)
cgroup      on  /sys/fs/cgroup/blkio             type  cgroup      (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup      on  /sys/fs/cgroup/cpuset            type  cgroup      (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup      on  /sys/fs/cgroup/perf_event        type  cgroup      (rw,nosuid,nodev,noexec,relatime,perf_event)
systemd-1   on  /proc/sys/fs/binfmt_misc         type  autofs      (rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
debugfs     on  /sys/kernel/debug                type  debugfs     (rw,relatime)
mqueue      on  /dev/mqueue                      type  mqueue      (rw,relatime)
hugetlbfs   on  /dev/hugepages                   type  hugetlbfs   (rw,relatime)
fusectl     on  /sys/fs/fuse/connections         type  fusectl     (rw,relatime)
tmpfs       on  /run/user/1000                   type  tmpfs       (rw,nosuid,nodev,relatime,size=204840k,mode=700,uid=1000,gid=1000)

And:

df -h /var/www
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        30G   20G  8.9G  69% /
  • Might be stupid question, please don't feel offended, but are you sure you are copying data to the location you really want to? Commands you specified should copy repo folder to /var/www/website/repo. Hope this is what you wanted to achieve. I don't believe linux is copying data and silently drops it. Any message? You could also add -v switch to your copy command to see what is going on. – Kalavan Oct 21 '16 at 12:49
  • @roaima ls -l index.html -rw-r--r-- 1 root root 98151 Oct 20 12:56 index.html – Kurt Van den Branden Oct 21 '16 at 13:49
  • @Kalavan: Yes, for testing purpose we copy everthing to a subfolder of /var/www/website. – Kurt Van den Branden Oct 21 '16 at 13:50
  • @KurtVandenBranden and the df please, just as I described – Chris Davies Oct 21 '16 at 15:13
  • Typo edit: df -h /var/www/website/repo/index.html returns /dev/vda1 30G 20G 8.8G 69% / – Kurt Van den Branden Oct 23 '16 at 11:13
  • ... So what happens instead? Error messages, cp -v, strace, lsattr? – frostschutz Oct 23 '16 at 11:27
  • 3
    Reduce the problem to a single or a few files (so they fit sanely in the question), the do an ls -l on the source files, and on the destination files before and after the copy. And post the commands you entered exactly. Something like 'ls -l /home/git/repo/foo ; ls -l /var/www/website/repo/foo ; cp -a /home/git/repo /var/www/website/ ; ls -l /var/www/website/repo/foo` – ilkkachu Oct 23 '16 at 14:04
  • 1
    As it is now, the question doesn't even show the files involved. Comments are a really bad way of adding information, as the formatting doesn't work well. (Also the ls -l listing a couple of comments up doesn't show where that index.html is located.) – ilkkachu Oct 23 '16 at 14:07
  • Is the server also running an NFS (server)? If so please show /etc/exports. Or is Samba running? Please also check what could be locking the file: fuser -v /var/www/website/repo/index.html. – Joshua Huber Oct 25 '16 at 16:31
  • 1
    From someone who's opened a bounty, I would expect a little more effort to include the details. Change your prompt, if you like, with PS1='\$ ', and then show the entire terminal output concisely that illustrates the difficulty you are having. Many good suggestions in the comments on how to do this, but the point is that it should be possible from reading the terminal output alone to see what your problem is. – Wildcard Oct 26 '16 at 02:04