LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-24-2017, 08:31 PM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Moving directories between different machines


My end goal is to copy the "directoryB" directory from machine1:/home/user1/directoryA/directoryB/ to machine2:/home/user2/someDirectory/directoryA/directoryB/. Or if easier, I am okay with just copying the files within the directoryB directory of machine1 to the coorisponding directory in machine2. The directoryB directory has multiple subdirectories and I would like to speed up the transfer time, and by intention is to use tar -cvzf.

A couple of details:

user1@machine1's public ssh key is in user3@machine2's authorized keys.
user2@machine1's public ssh key is in user1@machine2's authorized keys.
user1@machine2 has sudo access and can access user3@machine2's home directory.

I can create the tar and zip it easy enough, but the file structure just keeps on getting messed up no matter how I change -C starting/directory.

I don't need it to be the most concise way ever, and wish to keep things relatively simple and relatively concise.

How would you recommend doing this? Thanks
 
Old 11-24-2017, 08:46 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,384
Blog Entries: 28

Rep: Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164
I would recommend rsync. There's a bit of a learning curve, but it's well worth the effort.
 
Old 11-24-2017, 10:53 PM   #3
giis
Member
 
Registered: Nov 2013
Location: Third Rock from Moon
Distribution: RPM/DEB based and LFS
Posts: 73

Rep: Reputation: Disabled
Couple of ways, imo.

1 Use xz compression and rsync the .xz file
2 or simply rsync with archive option.
 
Old 11-25-2017, 12:54 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
As everyone has already mentioned, rsync is a good way to go. However, even though it uses SSH by default for the transport, you'll have to tell it which key to use via the -e option:

Code:
rsync -a -H -e 'ssh -i ~/.ssh/some_key' source  destination
 
Old 11-26-2017, 06:53 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
If you are having trouble with the -C option, how about
Code:
# src m/c
cd /blah/src_dir/
scp -r * user@target:/dir1/dir2/tgt_dir/
 
Old 11-26-2017, 07:52 PM   #6
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I don't think rsync uses ssh by default. I use it every day.
 
Old 11-26-2017, 07:54 PM   #7
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,384
Blog Entries: 28

Rep: Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164
I should have mentioned it last night, but there's also scp. I used it today to copy a directory from one machine to another.

There are some excellent examples here: https://haydenjames.io/linux-securel...les-using-scp/

The target machine must be running sshd (the ssh server daemon). The sending machine need only have the ssh client program installed.
 
Old 11-26-2017, 07:58 PM   #8
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,167

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
scp -r /path/to/directory someuser@serverB:/path/to/files/.

rsync -avz /source/path user@desthost:/destination/path/

rsync -avz -e 'ssh -p 2222' /source/path user@desthost:/destination/path/

source:
https://serverfault.com/questions/17...erver-to-other
https://superuser.com/questions/6081...nother-via-ssh

or try exploring Midnight Commander:
http://linuxcommand.org/lc3_adv_mc.php

Last edited by JJJCR; 11-26-2017 at 08:00 PM. Reason: edit
 
Old 11-26-2017, 08:19 PM   #9
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Yes, but is scp just a variation on the primitive cp, without error checking or anything?
 
Old 11-26-2017, 08:51 PM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,167

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Exclamation

Quote:
Originally Posted by AwesomeMachine View Post
Yes, but is scp just a variation on the primitive cp, without error checking or anything?
I'm not sure about it but I think there's a lot of difference.

Here's a thread from someone ascking scp source code:
https://www.linuxquestions.org/quest...e-code-539253/
 
Old 11-26-2017, 09:06 PM   #11
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,384
Blog Entries: 28

Rep: Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164Reputation: 6164
Per this link, scp does not do error checking by default, but I must say I've not encountered any errors in transferring files within my LAN via scp, and I've moved everything from text files to video files. Indeed, I'm watching one of those videos files as I type this and it has progressed flawlessly.

By the way, AwesomeMachine, excellent question.

Last edited by frankbell; 11-26-2017 at 09:13 PM.
 
Old 11-26-2017, 11:08 PM   #12
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Thanks frankbell. Why do you need scp inside the LAN? And, you might not find errors transferring 100 files. But when you start transferring 10,000 files or more it can become more of a problem.
 
Old 12-08-2017, 03:20 PM   #13
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AwesomeMachine View Post
Thanks frankbell. Why do you need scp inside the LAN?
Probably just my lack of understanding, but why is being on a LAN or WAN relevant?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Help: Bulk Moving from Sub-directories to directories vaneen Linux - Newbie 3 02-24-2016 04:11 AM
Syncronize directories in 3 machines lucazorzi Linux - Software 2 05-12-2009 10:12 AM
Moving LVM Between Machines... sancho Linux - Server 1 03-01-2008 09:38 AM
moving a file sequentially to different machines nightly mijohnst Programming 3 12-04-2005 05:44 PM
Moving Mozilla mail folders between machines rharvey@cox Linux - Software 6 02-13-2004 09:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration