We help IT Professionals succeed at work.

Check out this week's podcast, "Dairy Farms to Databases: Community's Hand in Technology"Listen Now

x

SCP Backup without overwriting and copying from remote to local

1,078 Views
Last Modified: 2013-12-26
Hey experts,

This is a tricky one:

I have two servers, the first one is a NAS and the second I`ll call XTREAMER (It's a media center with limited shell functions - running BusyBox).

XTREAMER has no rsync capability, but it`s able to connect to NAS without a password (ssh key installed)
NAS cannot connect via ssh to XTREAMER (installing ssh keys on XTREAMER does not work).

So basically I tought I could just copy files using scp:

On XTREAMER:
scp user@NAS:/nasfolder/ /xtreamerfolder/

Open in new window


The problem is that I`d like to check if the file is already on XTREAMER, and if it is I do not wish to copy it.

Can somebody help me out with a script that connects from XTREAMER to NAS, gets a list of files/folders on NAS, checks the ones that exist back on XTREAMER and scp those that do not exist on XTREAMER? (remember that ssh only works from XTREAMER to NAS so scp has to run on XTREAMER side)

Keep in mind that XTREAMER has really limited unix functions. I know ssh/scp is working fine though.

Thanks a lot, sorry I couldn`t come up with a code, unix programming is just not my thing :/

I hope I made myself clear :)
Comment
Watch Question

Top Expert 2010

Commented:
I dont think its possible with scp (without overwriting)

Author

Commented:
santoshmotwani, I`ve seen a script that can check from local to remote, I guess it just neets adaptation:


for FILE in $LOCAL_FILELIST
do
  OUT=`ssh remote_user@remote_hostname ls /remote_path/$FILE`
  if [ "$OUT" = "" ]
  then 
       echo "...copy File $FILE"
       scp  $FILE  remote_user@remote_hostname:/remote_path
   else 
       echo "...File already exist -> do nothing"
   fi
done

Open in new window

Author

Commented:
I.E.: I retrieved the list of files from NAS with:
[code]OUT='ssh user@NASMACHINE ls /path/to/files/'[/code]

Now I need to read "OUT" line by line and for those files that are not in the local directory, SCP them.

Help anyone?

Author

Commented:
Here's a little something I did... I just don't know why it keeps getting the contents of $LIST instead of running the script on $LIST. Can anyone help me out?
 
 

LIST='ssh user@NAS ls /PATH/TO/FILES/'
for FILE in $LIST
do
  OUT='ls /path/on/xtreamer/'
  if [ "$OUT" = "$FILE" ]
  then 
       echo "...File already exist -> do nothing"
   else 
       echo "...copy File $FILE"
       scp -r user@NAS:/path/to/files/$FILE /path/to/files/on/xtreamer/
   fi
done

Open in new window

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Exactly what I needed, thank you so much.

Author

Commented:
petriv, this solution does not parse directories with spaces (it creates directories with spaces but when it tries to enter them an error occurs, i.e.:

/ # ./copyfiles.sh
[/tmp/usbmounts/sda1/Filmes] creating ././Diary Of A Wimpy Kid
././Diary: No such file or directory.
./Of: No such file or directory.
./A: No such file or directory.
./Wimpy: No such file or directory.


any solutions?

Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.