I have jenkins on a remote machine and the pipeline scripts are saved in the path /var/lib/jenkins/jobs in .xml format files. I can easily list the .xml files that are in that folder with this command:

find /var/lib/jenkins/jobs -name config.xml

which results in:


From my local machine I have already managed to make the recursive copy of the folder in remote machine (Remote File to a Local Machine):

scp -r jenkins@ /mnt/c/backupJenkins/

What I would like to do is make a find that I described at the beginning of the question to use as input in scp.

There is a question that has already been asked here on the forum very similar, but the find command it uses on the local machine to transfer to remote:

scp --exec=`find <path> -name <expression>` user@host:<path_where_to_copy>

Here some attempts I've already made based on my internet research that I also adapted, but they didn't work:

scp jenkins@$`find /var/lib/jenkins/jobs -name config.xml` /mnt/c/backupJenkins
for f in `find /var/lib/jenkins/jobs -name config.xml`;do scp jenkins@$f /mnt/c/backupJenkins;done

An scp command looks like this:

scp [other options] [source username@IP]:/[directory and file name] [destination username@IP]:/[destination directory]

In 'other options' I think that passing the -p parameter would even be able to maintain the folder structure

  • Is there a reason why you can't just ssh into the remote sever first? If you were on the remote, your 2nd attempt would be close to correct. Sep 23 at 4:22

1 Answer 1


I can´t make work with a single command, but with two it worked

Command A: ssh jenkins@ 'cd /var/lib/jenkins/jobs; find . -name config.xml ! -path '*/backup*' | rsync -avz --files-from=- . ./backup'

'cd /var/lib/jenkins/jobs; - After ssh on my remote machine, I change directory to /var/lib/jenkins/jobs

find . -name config.xml ! -path '*/backup*' - Then make find and exclude the path of folder '/backup', this prevent rsync to copy 'backup' folder recursively.

rsync --files-from=- SRC/ DST/ using this format for the rsync command we add the parameters -avz and --files-from=-

| rsync -avz --files-from=- . ./backup' - The single dash - filename here means STDIN, and this is a common convention among unix tools

The command B we just use rsync to copy a File from a Remote Server to a Local Server with SSH, and save on my local machine on new folder DAY-MONTH-YEAR ( /mnt/c/backupJenkins/$(/bin/date +%d-%m-%Y) )

Command B: rsync -avz jenkins@* /mnt/c/backupJenkins/$(/bin/date +%d-%m-%Y)

New contributor
anijahzarri is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.