LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 09-19-2014, 11:05 AM   #1
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Rep: Reputation: Disabled
Rsync link destination on remote server


I am using rsync to back up a folder on a local machine to a remote machine.

The link destination folder is on the remote machine as is the target. When using the command line it works fine - using link-dest=../../link - that being the location relative to the target directory on the remote machine. When I try to put this into a script on the local machine it failed to exec --link-dest=../../link. In the script I have a variable LNK="../../link/" and TRG="remote@user:home/user/target. I am pretty new to scripting but this has stumped for a few days now.

I did try the full path on the LNK variable remote@user:home/user/link - same result

The fact that it seems to work from command line is bugging me and must be missing something in bash
Any help would be appreciated
Thanks
 
Old 09-19-2014, 11:18 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
would be nice to show the script, not only small parts.
 
Old 09-19-2014, 11:37 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
full path should be /home/user/link not home/user/link I suppose, no?

Quote:
LNK="../../link/" and TRG="remote@user:home/user/target
LNK relative path to TRG resolves to home/link
 
Old 09-19-2014, 11:50 AM   #4
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Here is the command line followed by the script. I ran rsync to make an initial full backup in the link-dest folder date stamped with the previous days date

rsync -avh -e "ssh -p 2346" /home/sysad/CurriculumVitae/ --link-dest=../../link/`date -I -d "1 day ago"` technicians@suppon.ns.ie:/home/technicians/Techapps/Howard/Backup/jobbies/`date -I`


#!/bin/bash

DAY0=`date -I`
DAY1=`date -I -d "1 day ago"`
SRC="/home/sysad/CurriculumVitae/"
TRG="technicians@suppon.ns.ie:/home/technicians/Techapps/Backup/jobbies/$DAY0"
LNK="../../link/$DAY1"

OPT="-avh -e `ssh -p 2346` --link-dest=$LNK"

rsync $OPT $SRC $TRG
 
Old 09-19-2014, 11:54 AM   #5
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Sorry keefaz typo
 
Old 09-19-2014, 12:28 PM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
I do not really understand. --link-dest=DIR is used to specify a reference dir on the remote side, see man page of rsync (so it is not a destination dir, but a place to link files from - instead of sending them across the line):
Code:
--link-dest=DIR
    This option behaves like --copy-dest, but unchanged files are hard linked from DIR to the destination directory. The files must be identical in all preserved attributes (e.g. permissions, possibly ownership) in order for the files to be linked together. An example: 
CW rsync -av --link-dest=$PWD/prior_dir host:src_dir/ new_dir/
If file's aren't linking, double-check their attributes. Also check if some
    attributes are getting forced outside of rsync's control, such a mount option that squishes root to a single user, or mounts a removable drive with generic ownership (such as OS X's lqIgnore ownership on this volumerq option). 
Beginning in version 2.6.4, multiple --link-dest directories may be
    provided, which will cause rsync to search the list in the order specified for an exact match. If a match is found that differs only in attributes, a local copy is made and the attributes updated. If a match is not found, a basis file from one of the DIRs will be selected to try to speed up the transfer. 
This option works best when copying into an empty destination hierarchy, as
    rsync treats existing files as definitive (so it never looks in the link-dest dirs when a destination file already exists), and as malleable (so it might change the attributes of a destination file, which affects all the hard-linked versions). 
Note that if you combine this option with --ignore-times, rsync will not
    link any files together because it only links identical files together as a substitute for transferring the file, never as an additional check after the file is updated. 
If DIR is a relative path, it is relative to the destination directory.
    See also --compare-dest and --copy-dest. 
Note that rsync versions prior to 2.6.1 had a bug that could prevent
    --link-dest from working properly for a non-super-user when -o was specified (or implied by -a). You can work-around this bug by avoiding the -o option when sending to an old rsync.
From the other hand your OPT variable is not set properly:
Code:
OPT="-avh -e \"ssh -p 2346\" --link-dest=$LNK"
and finally $(...) is preferred - instead of ` .... ` - you ought to use:
Code:
DAY0=$(date -I)
DAY1=$(date -I -d "1 day ago")
 
1 members found this post helpful.
Old 09-20-2014, 01:23 PM   #7
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks Pan64 I will test on Monday. I have the link-dest directory on remote machine as I didn't think hard links wouldn't work well spanning from local machine to remote machine. The destination directory is hard linked back to the link-dest directory right? If link-dest was on local machine then hard links would have to span to the remote destination folder
 
Old 09-20-2014, 02:36 PM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
link-dest is an existing dir on the remote server containing some/most of the files you want to sync (even it should be located on the same filesystem!). You are right, link-dest on the local host has no any meaning.
 
Old 09-24-2014, 10:57 AM   #9
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi pan64
I made the changes you suggested and I am getting Missing traling-" in remote-shell command?
 
Old 09-25-2014, 01:23 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
whould be nice to see the command or script.
 
Old 09-25-2014, 05:36 AM   #11
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Sorry


#!/bin/bash
DAY0=$(date -I)
DAY1=$(date -I -d "1 day ago")
SRC="/home/black1e/CurriculumVitae/"
TRG="technicians@techsrv.cs.tcd.ie:/home/technicians/Techapps/Howard/Backup/jobbies/$DAY0"
LNK="../../link/$DAY1"

OPT="-avh -e \"ssh -p 2346\" --link-dest=$LNK"

rsync $OPT $SRC $TRG
 
Old 09-25-2014, 06:11 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
probably you need rsync $OPT "$SRC" "$TRG"
insert a set -xv at the beginning of the script and you will see what will be executed. Can you post the result?

Last edited by pan64; 09-25-2014 at 06:13 AM.
 
Old 09-25-2014, 07:32 AM   #13
black1e
LQ Newbie
 
Registered: Sep 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hey I tried your suggestion with OPT SCR TRG no difference I also thought about their order and saw that the link dest is been called before the source directory - so I pulled the linked dest folder totally and got the missing trailing error again. I am running out of time on this one and might just stick it in to cron as is - it works from the command line - bit annoying though. Here is the result of set -xv





[black1e@vittry ~]$ ./cvback.sh
DAY0=`date -I`
date -I
++ date -I
+ DAY0=2014-09-25
DAY1=`date -I -d "1 day ago"`
date -I -d "1 day ago"
++ date -I -d '1 day ago'
+ DAY1=2014-09-24
SRC="/home/black1e/CurriculumVitae/"
+ SRC=/home/black1e/CurriculumVitae/
TRG="technicians@techsrv.cs.tcd.ie:/home/technicians/Techapps/Howard/Backup/jobbies/$DAY0"
+ TRG=technicians@techsrv.cs.tcd.ie:/home/technicians/Techapps/Howard/Backup/jobbies/2014-09-25
LNK="../../link/$DAY1"
+ LNK=../../link/2014-09-24

OPT="-avh -e \"ssh -p 2346\" --link-dest=$LNK"
+ OPT='-avh -e "ssh -p 2346" --link-dest=../../link/2014-09-24'

rsync $OPT $SRC $TRG
+ rsync -avh -e '"ssh' -p '2346"' --link-dest=../../link/2014-09-24 /home/black1e/CurriculumVitae/ technicians@techsrv.cs.tcd.ie:/home/technicians/Techapps/Howard/Backup/jobbies/2014-09-25
Missing trailing-" in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.6]
 
Old 09-25-2014, 09:27 AM   #14
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
here you can find an explanation: http://superuser.com/questions/35436...-a-bash-script and a way to solve it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
rsync and tar files in remote server Iyyappan Linux - Server 6 04-18-2014 07:19 AM
Rsync logging on destination when using remote-shell connection wernervz Linux - Software 1 06-08-2013 01:35 AM
[SOLVED] rsync always writing backup to /home/ on remote server HellesAngel Linux - Networking 6 02-16-2011 09:26 AM
[SOLVED] RSYNC Creates New Folder Every Time (on remote server). cryingthug Linux - Server 1 09-09-2010 07:48 AM
Rsync connecting to a remote server Rudy Linux - Software 8 08-28-2009 01:09 PM


All times are GMT -5. The time now is 09:26 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration