cp -R vs rsync -pvzar

So what’s the difference between cp -R and rsync -pvzar?

From man cp:

-R If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the
source_file ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes
symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as
normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process’
umask.

In -R mode, cp will continue copying even if errors are detected.

Note that cp copies hard-linked files as separate files. If you need to preserve hard links, consider using tar(1),
cpio(1), or pax(1) instead.

So:

  • recursively copy
  • copy symlinks
  • create special files rather than copying them as
    normal files
  • directories have same mode as source

 

From man rsync and looking at pvzar individually:

  •  -p, –perms preserve permissions
  • -v, –verbose increase verbosity
  • -z, –compress
    With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of
    data being transmitted — something that is useful over a slow connection.

    Note that this option typically achieves better compression ratios than can be achieved by using a compressing remote
    shell or a compressing transport because it takes advantage of the implicit information in the matching data blocks that
    are not explicitly sent over the connection.

  • -a, –archive
    This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission). The only exception to the above equivalence is when –files-from is specified, in which case -r is not implied.

    Note that -a does not preserve hardlinks, because finding multiply-linked files is expensive. You must separately specify -H.

  • -r, –recursive
    This tells rsync to copy directories recursively. See also –dirs (-d).

 

Note:

-H, –hard-links
This tells rsync to look for hard-linked files in the transfer and link together the corresponding files on the receiving side. Without this option, hard-linked files in the transfer are treated as though they were separate files.

Note that rsync can only detect hard links if both parts of the link are in the list of files being sent.

Docker Volumes vs Bind Mounts

Bind mount

File or directory on host mounted into container. You refer to this file/directory using the full file path used on the host.

The problem with a bind mount is you have to have the full host file path which may be different on different hosts. E.g. if you use /Users/dave it’s going to break if someone else doesn’t have a Users/dave directory.

Volume

While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. They’re created in  /var/lib/docker/volumesand you refer to them by name. E.g.

-v mysql_data:/containerdir

Here’s what this means:

  • the first field is the name of the volume. It’s unique on a given host machine
  • the second field is the path where the file or directory are mounted in the container

https://docs.docker.com/storage/bind-mounts/

https://docs.docker.com/storage/volumes/#choose-the–v-or—mount-flag

https://stackoverflow.com/questions/47150829/what-is-the-difference-between-binding-mounts-and-volumes-while-handling-persist