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



## Alain De Vos (Aug 27, 2020)

I want to avoid using rsync.
I also want to avoid copying everything cp -axfvR ...
Which easy and good tools exist ?

I think tool below is for linux,








						GitHub - Fitus/Zaloha.sh: (obsolete version) Small and simple directory synchronizer
					

(obsolete version) Small and simple directory synchronizer - GitHub - Fitus/Zaloha.sh: (obsolete version) Small and simple directory synchronizer




					github.com
				




I think unison is more for merging backups (but could be wrong)


----------



## VladiBG (Aug 27, 2020)

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_.


----------



## Deleted member 63539 (Aug 27, 2020)

Alain De Vos said:


> I want to avoid using rsync.
> I also want to avoid copying everything cp -axfvR ...
> Which easy and good tools exist ?
> 
> ...


sysutils/cpdup

`cpdup -vvv /test1 /test2`


----------



## obsigna (Aug 27, 2020)

sysutils/clone -- clone(1)


----------



## T-Daemon (Aug 27, 2020)

net/unison

unison-manual - Local Usage


----------



## kpedersen (Aug 27, 2020)

Perhaps consider standard version control systems (i.e svn, git)?
Depending on the task they might be overkill however.


----------



## SKull (Aug 27, 2020)

Alain De Vos said:


> I want to avoid using rsync.


I'm sorry, I have to ask: Why?


----------



## kpedersen (Aug 27, 2020)

SKull said:


> 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.


----------



## olli@ (Aug 27, 2020)

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.


----------



## Phishfry (Aug 27, 2020)

kpedersen said:


> Dislikes running programs beginning with the letter 'r'


So I guess my recommendation of net/rclone using a local target will be moot.





						Local Filesystem
					

Rclone docs for the local filesystem




					rclone.org
				



We even have a GUI front end in ports. net/rclone-browser/


----------



## kpedersen (Aug 28, 2020)

Phishfry said:


> 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..."


----------



## olli@ (Aug 28, 2020)

Phishfry said:


> 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).


----------



## ekvz (Aug 28, 2020)

It shouldn't be to hard to script this. Maybe something along those lines:


```
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.


----------



## Alain De Vos (Aug 28, 2020)

I didn't liked too much rsync ...
What i now do is the following :

```
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",

```
PORT_SRC="/mnt/ports_download"
PORT_DEST="/poudriere/jailsandports/ports/QUARTERLY"
clone -x ".svn" -s -v 0 -- ${PORT_SRC}/   ${PORT_DEST}/
```


----------



## wolffnx (Aug 29, 2020)

I had nothing against rsync, of course,the only times I used it if for resume SCP bkoken file transfers


----------

