Hello! Need a help.
The task is:
Connect from local to remote, find there some files and SCP them to the local from remote.
Now I'm use (and it works well):
scp -r user@server:/some/directory /home/backups
but I want to copy only FIND /some/directory -mtime +1
How I can compose both this command?
P.S.
I know, that exist a metod:
find /some/directory -mtime +1 -exec scp -r /some/directory user@server:/home/backups {} \;
but I need to initialise connection from the local computer, not from remote.
SCP + FIND from local [SOLVED]
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
SCP + FIND from local [SOLVED]
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
- Pilosopong Tasyo
- Level 6
- Posts: 1432
- Joined: Mon Jun 22, 2009 3:26 am
- Location: Philippines
Re: SCP + FIND from local
Use
ssh
to run the find
command remotely that will eventually scp
those files from the remote machine to the local host, i.e. ssh <user@server> <command>
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
Re: SCP + FIND from local
Yea, that's true, but I can't find the correct syntax.Pilosopong Tasyo wrote: ⤴Wed Jul 25, 2018 7:03 pm Usessh
to run thefind
command remotely that will eventuallyscp
those files from the remote machine to the local host, i.e.ssh <user@server> <command>
Re: SCP + FIND from local
scp
is a bit annoying in this regard seeing as how it doesn't automatically create leading directories; I'd advise using rsync
. I.e.,Code: Select all
rsync -avn --files-from <(ssh user@server find /some/directory -mtime +1 -printf "%P\\\n") user@server:/some/directory /home/backups/
Re: SCP + FIND from local
Code: Select all
for i in $(ssh user@server find /some/directory -type d -mtime +1);
do
scp -r user@server:$i /home/backups
done
Code: Select all
for i in $(ssh user@server ~/find_my_dirs);
do
scp -r user@server:$i /home/backups
done
If you meant which directory is to be searched for relevant files you can do that:
Code: Select all
for i in $(ssh user@server "~/find_my_files $SEARCH_DIR);
do
scp -r user@server:$i /home/backups
done
Re: SCP + FIND from local
Thank you! That is just what I need. And this solution works!rene wrote: ⤴Fri Jul 27, 2018 8:35 amscp
is a bit annoying in this regard seeing as how it doesn't automatically create leading directories; I'd advise usingrsync
. I.e.,
Remove the -n (--dry-run) once satisfied this does what you want.Code: Select all
rsync -avn --files-from <(ssh user@server find /some/directory -mtime +1 -printf "%P\\\n") user@server:/some/directory /home/backups/