Foad S. Farimani
Foad S. Farimani

Reputation: 14056

How to make a bash function to run a bidirectional rsync

I have a local folder and a remote one on a server with ssh connection. I don't have admin privileges so installing new packages are not possible to use unison for example. I have to sync these two folders quite often and they are also big. From here I know that to sync in both sides I have to rsync twice. once from server to local:

rsync -Przzuve ssh user@server:/path/to/remote/folder/* /path/to/local/folder

and then the other way around, from local to server

rsync -Przzuve ssh /path/to/local/folder/* user@server:/path/to/remote/folder

What I want to have is a single command like:

rsyncb /path/to/local/folder user@server:/path/to/remote/folder

To just sync the content of two folders in both directions in one command without worrying about the -* options and /* at the end of the first path...

I found this about making a bash function with given arguments but I do not understand how to implement what I want. I would appreciate if you could help me with this.

Upvotes: 2

Views: 1711

Answers (1)

Ben Harris
Ben Harris

Reputation: 557

Just define a function.

rsyncb() {
    rsync -Przzuve ssh "$1"/* "$2"
    rsync -Przzuve ssh "$2"/* "$1"
}

Then use it like this:
rsyncb user@server:/path/to/remote/dir /path/to/local/dir

Upvotes: 4

Related Questions