Unexpected local arg: /rsync - rsync

I would like to use rsync to synchronise my /rsync folder.
I create the rsync users on my 2 servers and configure the ssh key.
I installed rsync, created /rsync folder put chmod 777 on it.
But when I execute
rsync -avz -e ssh rsync#1.2.3.4:/rsync /rsync -p 8682
I have
Unexpected local arg: /rsync
If arg is a remote file/dir, prefix it with a colon (:).
rsync error: syntax or usage error (code 1) at main.c(1246) [Receiver=3.0.9]
("ssh rsync#1.2.3.4 -p 8682" works)

rsync -avz -e 'ssh -p 8682' rsync#1.2.3.4:/rsync /rsync

Related

Using rsync with gitlab-ci how to deploy identically?

when I push and that, on my server, I don't have my project, everything is fine (obviously):
rsync --exclude=".git" -e ssh -avz --delete-after . $SSH_USER#$SSH_HOST:blog_symfony/
building file list ... done
created directory blog_symfony
[...]
sent 44,533,927 bytes received 5,523 bytes 5,239,935.29 bytes/sec
total size is 238,959,003 speedup is 5.37
the problem when I push a 2nd time, it does anything to me:
rsync: [generator] delete_file: rmdir(project/blog_symfony/project/blog_symfony) failed: Permission denied (13)
rsync: [generator] delete_file: rmdir(project/blog_symfony) failed: Permission denied (13)
deleting project/blog_symfony/translations/.gitignore
deleting project/blog_symfony/translations/
[...]
it creates for me, on my server side, a 'project' folder in the blog_symfony folder
annot delete non-empty directory: project/blog_symfony
cannot delete non-empty directory: project
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
sent 13,924 bytes received 175 bytes 28,198.00 bytes/sec
total size is 238,959,004 speedup is 16,948.65
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1
my gitlab-ci:
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
script:
- ls
- apt-get update && apt-get install rsync -y
- ssh $SSH_USER#$SSH_HOST "ls"
- rsync --exclude=".git" -e ssh -avz --delete-after . $SSH_USER#$SSH_HOST:blog_symfony/
- ssh $SSH_USER#$SSH_HOST "cd blog_symfony && docker-compose build && docker-compose up"
in ls -l I have a folder written by rsync and which is impossible to remove from gitlab-ci:
drwxrwxr-x 3 root root 4096 Dec 14 23:26 project
I don't think this is normal. This is the first time that I use gitlab-ci for a symfony project.
Thank you for your help
ls -l: I have a folder written by rsync and which is impossible to remove from GitLab CI.
Check if that folder is instead created after the first execution of your docker-compose up: if your Docker image execute itself internally as USER root, using a bind mount, it would write files/folders as root.
And that would impede normal operation (on the server, outside the container), like your rsync, because root files would be i the way.

scp -r does not seem to work on zsh, no idea why

I can scp files to a remote host, but if I try to scp -r a directory it does not work
scp -r mydir me#remote.host:/where/the/dir/has/to/go/
scp: realpath /whatever/mydir: No such file
scp: upload "/whatever/mydir": path canonicalization failed
scp: failed to upload directory cf2t to /where/the/dir/has/to/go/
I thought it was some issue with globbing, so I quoted different parts of the damn command to no avail.
on remote.host: mkdir -p /where/the/dir/has/to/go/
on local host: scp -r mydir me#remote.host:/where/the/dir/has/to/go/

rsync: create target directory on server over ssh tunnel?

When using rsync, it is possible to create the target directory on the server using the --rsync-path trick as follows:
rsync -av -e "ssh" --rsync-path "mkdir -p /home/user/new/new && rsync" ./file.txt user#10.0.2.60:/home/user/new/new
This however does not seem to work when using an ssh tunnel. The following command just hangs:
rsync -av -e "ssh -A user#10.0.2.61 ssh" --rsync-path "mkdir -p /home/user/new/new && rsync" ./file.txt user#10.0.2.60:/home/user
I have verified the last command works if I remove the --rsync-path argument and create the directory manually on the target device. But how to make rsync create the missing directory when using ssh tunneling?
Managed to solve it. The command inside --rsync-path must be wrapped in another level of quotes:
rsync -av -e "ssh -A user#10.0.2.61 ssh" --rsync-path "'mkdir -p /home/user/new/new && rsync'" ./file.txt user#10.0.2.60:/home/user

rsync -- command-line for syncing from local to remote over ssh

I'm looking for some assistance please to create a proper command-line for syncing from a local machine to a remote server over ssh.
Here is a draft that is not working.
/usr/bin/rsync --dry-run --delete -arzh /Users/HOME/.0.data/ "--rsh=/Users/HOME/.0.data/.0.emacs/elpa/bin/sshpass -p 'alpine' ssh -p '2222' -l root localhost" -t "cd /var/mobile/Applications/F30B1574-5979-4764-8742-7F9DB2863094/Documents/.0.data && bash --login"
The following command-line successfully logs in to my iphone over ssh via usb. Id like to incorporate that working command-line into something that can be used with rsync, but I need some assistance in that regard.
/Users/HOME/.0.data/.0.emacs/elpa/bin/sshpass -p 'alpine' ssh -p '2222' -l root localhost -t "cd /var/mobile/Applications/F30B1574-5979-4764-8742-7F9DB2863094/Documents/.0.data && bash --login"
For anyone who is interested in leaning how to ssh into an iphone over usb, here is a link that discusses the method: http://iphonedevwiki.net/index.php/SSH_Over_USB
rsync must be installed on both locations. Cydia has an rsync binary that installs on the iPhone. The method of connection with rsync is the same as any regular ssh sever.
Here is a bash script solution (includes --dry-run):
#!/bin/bash
HOST="localhost";
PORT="2222";
USER="root";
PWD="alpine";
SOURCE="/Users/HOME/Desktop/test/";
TARGET="/private/var/mobile/Applications/F30B1574-5979-4764-8742-7F9DB2863094/Documents/test";
SSHPASS="/Users/HOME/.0.data/.0.emacs/elpa/bin/sshpass";
RSYNC="/Users/HOME/.0.data/.0.emacs/elpa/bin/rsync";
$RSYNC --dry-run --progress --delete -arvzh --rsh="$SSHPASS -p $PWD ssh -p $PORT -l $USER" $SOURCE $HOST:$TARGET
For an example of how to use rsync in conjunction with Emacs, see the following thread: https://emacs.stackexchange.com/a/5844/2287

How do I rsync a file to a remote directory that doesn't exist?

Suppose I want to rsync file foo.txt on my local machine to file /home/me/somedirectory/bar.txt on a remote computer, and that somedirectory/ doesn't yet exist. How do I do this?
I tried rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt, but I get a rsync: push_dir#3 "/home/me/somedirectory" failed: No such file or directory (2) error.
(Copying the file without renaming it works, though. That is, this runs fine: rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/`)
Just put a trailing slash on your target dir. Something like this:
rsync foo.txt remotemachine:somedirectory/
Assuming that "/home/me" is your home dir on the remote machine, there is no need to specify it in the command line. Also, you don't need to clutter up your rsync with the -e unless you just like to do that.
You can do this process successfully in 2 stepes:-
1] rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/
this will copy the foo.txt and create directory somedirectory on destination.
then
2] rsync -e ssh -z --delete-after foo.txt remotemachine:/home/me/somedirectory/bar.txt
and here you can delete foo.txt on destination by using --delete-after option.
you can see it's usage from man pages. This option must be used with -r option
This serves your purpose.
or if second command doesn't work then use :-
rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt
and delete foo.txt manually.

Resources