2

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.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • 2
    Aliases can't process parameters, you need to use a function. – Barmar Jan 29 '18 at 17:13
  • 2
    The first answer in the question you linked to says that in the first sentence. – Barmar Jan 29 '18 at 17:13
  • @Barmar thanks a lot for your comment and downvote – Foad S. Farimani Jan 29 '18 at 17:16
  • Could you explain what part of the linked question is unclear / how you tried to apply its advice and failed? Right now it's unclear what part of what you're trying to do isn't already answered there (and thus why this isn't simply a duplicate). Please be as specific as possible (ie. "the answer advises Y, but when I try that I get Z"). – Charles Duffy Jan 29 '18 at 17:22
  • @CharlesDuffy It was not clear to me for example how to add the `/*` part at the end of the path and other issues – Foad S. Farimani Jan 29 '18 at 17:25
  • 1
    If adding the `/*` is your problem, it sounds more like you have a question about how to concatenate strings to form an argument list than like a question about bash functions. If what you really had is, say, two or three separate questions, then they should be broken out and searched for individually (I'd say "and asked" if the search failed, but we already have perfectly good knowledgebase entries about string concatenation, and probably whatever the other specific points of confusion were). – Charles Duffy Jan 29 '18 at 17:31
  • @CharlesDuffy thanks for your comments. There were more questions which I didn't know how to ask. I'm a bash novice. I will consider your points next time. – Foad S. Farimani Jan 29 '18 at 17:33

1 Answers1

4

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

June7
  • 19,874
  • 8
  • 24
  • 34
Ben Harris
  • 547
  • 3
  • 10