Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Using rsync --link-dest pointing to a remote server

--link-dest, remote, rsync, ssh

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-21-2013
Orionizer Orionizer is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 25 June 2013, 1:48 PM EDT
Location: North Carolina, USA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Using rsync --link-dest pointing to a remote server

Ok, I'm trying to figure out how to reference a remote file using the rsync --link-dest parameter.

Here is the code I have so far:

Code:
#
# FILESERVER INCREMENTAL BACKUP SCRIPT
#

# Remove previous log file

rm /usr/local/bin/rsync-incremental.log

# Set daily variables

DAY0=`date -I`
DAY1=`date -I -d "1 day ago"`
DAY6=`date -I -d "2 days ago"`
DAY7=`date -I -d "3 days ago"`
DAY8=`date -I -d "4 days ago"`

# Set rsync variables

SRC="/usr/smbshares"
TRG="root@synology1:/volume1/Fileserver/$DAY0"
LNK="root@synology1:/volume1/Fileserver/$DAY1"
OPT="-avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --link-dest=$LNK"

# Remove old backups

ssh root@synology1 "if [[ -d /volume1/Fileserver/$DAY6 ]]; then nohup rm -rf "/volume1/Fileserver/$DAY6"; fi"

ssh root@synology1 "if [[ -d /volume1/Fileserver/$DAY7 ]]; then nohup rm -rf "/volume1/Fileserver/$DAY7"; fi"

ssh root@synology1 "if [[ -d /volume1/Fileserver/$DAY8 ]]; then nohup rm -rf "/volume1/Fileserver/$DAY8"; fi"

# Perform the rsync

rsync $OPT $SRC $TRG

Everything is working now except the --link-dest parameter. I get the following error at the beginning of execution:

--link-dest arg does not exist: root@synology1:/volume1/Fileserver/2013-06-20

What's funny is the rsync has no issue using the same syntax for the target folder of the command...

Anyone know how to reference the remote file for this?

Thanks!

---------- Post updated at 01:52 PM ---------- Previous update was at 01:31 PM ----------

If anyone is wondering, I'm trying to accomplish backing up a SLES Samba server to a remote Synology NAS. I want to keep 5 days worth of backups on the NAS, but only the original or changed files. Not backing up ALL files all five days.

If a backup folder exists that is 6, 7 or 8 days old, I want to remove it to keep files from accumulating on the NAS over time.

I know the $DAY6, etc. variables are wrong as I changed them for testing purposes.

So that's what I'm trying to accomplish. If you can think of any better way to accomplish this, I'd be glad to give that a shot as well, but from what I've read it seems rsync is pretty reliable and quick.

As it's working right now, I am getting the 5 days worth of backups, but it's copying every file every time as the --link-dest isn't working.
Sponsored Links
    #2  
Old 06-21-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 February 2016, 3:35 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,673
Thanks: 8
Thanked 588 Times in 561 Posts
That option is for two subtrees on the same device locally. It makes a clone tree with the same inode present in the same relative directory of both ssubtrees. Hard link means same device of same machine.
Sponsored Links
    #3  
Old 06-21-2013
Orionizer Orionizer is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 25 June 2013, 1:48 PM EDT
Location: North Carolina, USA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, so is there another solution?

---------- Post updated at 06:08 PM ---------- Previous update was at 05:56 PM ----------

I may have found something. I'll post any results.

---------- Post updated at 07:59 PM ---------- Previous update was at 06:08 PM ----------

I am testing the following code:

Code:
#
# FILESERVER INCREMENTAL BACKUP SCRIPT
#

# Remove previous log file

rm /usr/local/bin/rsync-incremental.log

# Set variables

BACKUPDIR=`date +%A`
SRC="/usr/smbshares/"
TRG="root@synology1:/volume1/Fileserver/Current"
OPT="-avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --backup --backup-dir=$BACKUPDIR"

# Remove old backups

rsync --delete -a /usr/local/bin/emptydir/ root@synology1:/volume1/Fileserver/$BACKUPDIR/

# Perform the rsync

rsync $OPT $SRC $TRG

Will let you know how things turn out over the weekend...
    #4  
Old 06-24-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 February 2016, 3:35 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,673
Thanks: 8
Thanked 588 Times in 561 Posts
There is no doubt that rsync can make a remote copy, and can be set to maintain it in real time, too. Make a little subtree to play with, and get the feel of it. You can option it for security using ssh, and for compression using ssh -C, which sometimes helps lighten net load and speed things up.

If you want to keep some dialy states, you can make a clone tree (same subdirectories, all files hard linked from source subtree) remotely to back up to if different, so all unchanged files are stored in one inode for all consecutive versions. Users love to be able to ge a file as it way N days ago, or peruse the back versions. Just option rsync to delete before overwrite, as a write to a hard linked file updates all versions.

There may be tools that run on top of rsync or use similar methods and manage this sort of backup for you. In the Internet Age, you have to imagine and Google.
Sponsored Links
    #5  
Old 06-25-2013
Orionizer Orionizer is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 25 June 2013, 1:48 PM EDT
Location: North Carolina, USA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, thanks for that additional info.

However, looking at the script, I'm thinking this should definitely work, but for some reason, nothing is ever getting copied into the backup directory. It creates the backup directory, but nothing is ever placed into it.

Here is the code I'm running:

Code:
#
# FILESERVER INCREMENTAL BACKUP SCRIPT
#

# Remove previous log file

rm /usr/local/bin/rsync-incremental.log

# Set variables

BACKUPDIR=`date +%A`
SRC="/usr/smbshares/"
TRG="root@synology1:/volume1/Fileserver/Current/"
OPT="-avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --backup --backup-dir=$BACKUPDIR"

echo BACKUPDIR > /usr/local/bin/rsync-incremental.log
echo $BACKUPDIR >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log

# Remove old backups

rsync --delete -a /usr/local/bin/emptydir/ root@synology1:/volume1/Fileserver/$BACKUPDIR

echo SOURCE >> /usr/local/bin/rsync-incremental.log
echo $SRC >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log
echo TARGET >> /usr/local/bin/rsync-incremental.log
echo $TRG >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log
echo OPT >> /usr/local/bin/rsync-incremental.log
echo $OPT >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log

# Perform the rsync

rsync $OPT $SRC $TRG

Here is the top of the rsync-incremental.log file with the variables spelled out:

BACKUPDIR
Tuesday
------------------
SOURCE
/usr/smbshares/
------------------
TARGET
root@synology1:/volume1/Fileserver/Current/
------------------
OPT
-avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --backup --backup-dir=Tuesday
------------------


So the rsync line passed is:

Code:
rsync -avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --backup --backup-dir=Tuesday /usr/smbshares/ root@synology1:/volume1/Fileserver/Current/

But, as I said, nothing is ever copied into the Tuesday folder! It is created, but nothing is under it. Also, there are definite changes made to SEVERAL HUNDRED files per day under /usr/smbshares, I can assure you.

Now, to test, I took one of the subdirectories under /usr/smbshares and typed the following line:

Code:
rsync -avhz -e ssh --delete --backup --backup-dir=darrellpbackup /usr/smbshares/darrellp root@synology1:/volume1/Fileserver/

I then went and made a small change to one of the files and performed again and it backed up the previous copy of the file in the backup folder!

Can you guys see anything I'm missing here?

---------- Post updated at 10:45 AM ---------- Previous update was at 09:53 AM ----------

Ok, I've figured this out somewhat.

It is creating a folder under /volume1/Fileserver/Tuesday, but it is ALSO creating a folder under /volume1/Fileserver/Current/Tuesday.

The second is where the backups are being placed, but the first is the empty (and that's where I've been looking for the backup files).

Any idea based on the rsync command why it would create the 1st folder?

Thanks!

---------- Post updated at 01:09 PM ---------- Previous update was at 10:45 AM ----------

Ok, after fiddling some more, I've changed my code to:

Code:
#
# FILESERVER INCREMENTAL BACKUP SCRIPT
#

# Remove previous log file

rm /usr/local/bin/rsync-incremental.log

# Set variables

BACKUPDIR=`date +%A`
SRC="/usr/smbshares/"
TRG="root@synology1:/volume1/Fileserver/Current/"
OPT="-avhz -e ssh --log-file=/usr/local/bin/rsync-incremental.log --delete --backup --backup-dir=/volume1/Fileserver/$BACKUPDIR"

echo BACKUPDIR > /usr/local/bin/rsync-incremental.log
echo $BACKUPDIR >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log

# Remove old backups

rsync --delete -a /usr/local/bin/emptydir/ root@synology1:/volume1/Fileserver/$BACKUPDIR

echo SOURCE >> /usr/local/bin/rsync-incremental.log
echo $SRC >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log
echo TARGET >> /usr/local/bin/rsync-incremental.log
echo $TRG >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log
echo OPT >> /usr/local/bin/rsync-incremental.log
echo $OPT >> /usr/local/bin/rsync-incremental.log
echo ------------------ >> /usr/local/bin/rsync-incremental.log

# Perform the rsync

rsync $OPT $SRC $TRG

Seems to be working so far and will let you know after a day or two to make sure things are being backed up to the appropriate folder. What was happening is the "Clear" rsync was going to one folder where the "Backup" rsync was going to the other one. By specifying the "Backup" folder including the path, they now point to the same folder. Just wasn't sure if that would work via the rsync since I was specifying a path on the remote server, but seems to like it!

Last edited by Orionizer; 06-25-2013 at 01:23 PM..
Sponsored Links
    #6  
Old 06-25-2013
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 16 July 2018, 9:56 AM EDT
Location: Switzerland - GE
Posts: 6,550
Thanks: 311
Thanked 564 Times in 526 Posts
Thanks for the updates!
Sponsored Links
    #7  
Old 06-25-2013
Orionizer Orionizer is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 25 June 2013, 1:48 PM EDT
Location: North Carolina, USA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
No problem! Hoping this works and, of course, will let you know one way or the other. I do believe I've nixed the issue though!

I should also state, sorry for being so rusty. The last time I worked on any serious shell scripts was in college in 1990 or so (on an AT&T UNIX box), so I'm quite out of practice.
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with rsync using link-dest lost.identity UNIX for Dummies Questions & Answers 1 05-09-2012 06:40 AM
How to create a sym link pointing a changing name. vra5107 AIX 1 08-20-2010 09:54 PM
rsync with --link-dest doesn't create hard links fitzwilliam UNIX for Dummies Questions & Answers 0 07-10-2010 12:21 AM
How to write a shell script for rsync to remote server? Desperados Shell Programming and Scripting 0 06-04-2010 09:57 AM



All times are GMT -4. The time now is 04:54 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?