How to synchronise two directories on the same host without using rsync

Your best choice is rsync.
You can use pax(1) to copy the files but it will not remove the existing files from the target directory if they were removed in the source directory.

The command:
pax -r -w -v -Y -Z home /backup
will update (and list) only those files in the destination directory
/backup which are older (less recent inode change or file modification
times) than files with the same name found in the source file tree home.
 
I'm sorry, I have to ask: Why?

I was wondering the same for far too long. These are all I could come up with:
  • Dislikes running programs beginning with the letter 'r'
  • rsync is not in base install
  • Windows rsync implementations suck (or need to install entire POSIX layer)
Consider me intrigued.
 
My recommendation is sysutils/cpdup.

net/unison is useful if you need two-way synchronisation, i.e. when files get modified on both sides, and you need the changes to be propagated in both directions.

I also dislike rsync. Last time I looked at the source, it was rather badly written and had insufficient error checking. For example, when no space was left on the target file system, rsync ran havoc and deleted files randomly. Not good. Since then I try to avoid it.

By the way, using cp(1) to duplicate a directory tree is not a good idea, because it doesn’t make an exact copy (it breaks hardlinks, for example). Actually, I think it was a mistake to add the -r and -R options to cp(1). It’s better to use tar(1) or find(1)+cpio(1), or one of the tools from the ports collection like sysutils/cpdup.
 
So I guess my recommendation of net/rclone using a local target will be moot.

Well since that tool looks pretty good, we might want to consider asking the authors if they would be willing to rename their project for us first?

We could start the email off with "Your MIT license is great but your project begins with the letter 'r'. This is disappointing to me and I feel..."
 
So I guess my recommendation of net/rclone using a local target will be moot.
Seriously, that tool might be good for mirroring stuff to/from cloud services, but it isn’t really well suited for local copies. It does not copy links, it does not handle permissions and flags (and apparently it also does not handle owner and group), and it only supports UTF8-encoded file names (it should at least have an option to just treat file names as byte sequences without interpretation).
 
It shouldn't be to hard to script this. Maybe something along those lines:

Code:
case $1 in
    sync)
        find "$2" -exec "$0" src "$2" "$3" {} \;
        find "$3" -exec "$0" dst "$2" "$3" {} \;
        exit 0
        ;;
    src)
        P="$( echo "$4" | cut -b$( echo "$2" | wc -c )- )"
        [ -e "$3/$P" ]; E=$(( !$? ))
        if [ -d "$1" ]; then
            [ "$E" = 0 ] && mkdir -p "$3/$P"
        elif [ -f "$1" ]; then
            if [ "$E" = 0 ]; then
                mkdir -p "$( dirname "$3/$P" )"
                cp "$4" "$3/$P"
            fi
        elif [ -L "$1" ]; then
            T="$( readlink -f "$4" )"
            if [ "$E" = 0 ]; then
                ln -s "$( readlink -f "$4" )" "$3/$P"
            elif [ ! "$T" = "$( readlink -f "$3/$P" )" ]; then
                rm "$3/$P"
                ln -s "$( readlink -f "$4" )" "$3/$P"
            fi
        fi
        ;;
    dst)
        P="$( echo "$4" | cut -b$( echo "$3" | wc -c )- )"
        [ -e "$2/$P" ] || rm -rf "$4"
        ;;
    *)
        echo "USAGE: $0 sync [SRC] [DST]" >&2
        exit 1
        ;;
esac

WARNING: This is entirely untested and also contains rm -rf. Use only with extreme caution! I don't take responsibility if there is a bug making it delete everything in sight.
 
I didn't liked too much rsync ...
What i now do is the following :
Code:
MYDIR="/mnt/ports_download"
svn checkout  --trust-server-cert --non-interactive https://svn.freebsd.org/ports/branches/2020Q3/ ${MYDIR}
And then before starting the "manual poudriere jail",
Code:
PORT_SRC="/mnt/ports_download"
PORT_DEST="/poudriere/jailsandports/ports/QUARTERLY"
clone -x ".svn" -s -v 0 -- ${PORT_SRC}/   ${PORT_DEST}/
 
Back
Top