2

This is my first attempt at a shell script. I'm simply trying to make incremental copies of certain folders from a server to another server using Rsync, but using the link-dest option to create hardlinks to unmodified files. When I check the folder structure file sizes as they exist in the folder 'Editshare_Backups' I see that they appear to be just as large as each other. I am using du -sh * inside the 'Editshare_Backups' folder as I was under the impression that du doesn't count a second hard link when calculating size.

I used stat -f %l on a specific file inside the first full backup and it shows only 1 hard link.

What other options are there for checking whether hard links have been made?

Code from my shell script is:

#!/opt/bin/bash

#Rsync Editshare Database Backups Script

#Todays date
TODAY=`date -I`

#Yesterdays date
PREVIOUS_DAY=`date -I`

#The source directory:

SRC1="/RAIDS/RAID_2"
SRC2="/etc" 
SRC3="/var/lib"

#The target directory:
TRG="/volume1/Editshare_Backups/$TODAY"

#The link destination directory:
LNK="/volume1/Editshare_Backups/$PREVIOUS_DAY"

#The rsync options:
OPT="-avh -e ssh --delete --progress --link-dest=$LNK"

#Log file:
LOG="/volume1/Editshare_Backups/Logs/Log_$TODAY.log"

#Execute the backup
rsync $OPT [email protected]:$SRC1 :$SRC2 :$SRC3 $TRG >> $LOG 2>&1
3
  • Your link-dest PREVIOUS_DAY is the same as TODAY, so no links can be made.
    – meuh
    Jul 19, 2016 at 9:15
  • aha! thankyou! Still finding after making this change though that du -sh * shows the folders as being both large, i.e the second one hasnt copied only incremental changes and hard linked to the first. The LOG though shows only 9GB was transferred which makes me believe it did hard link?
    – C. Ricker
    Jul 21, 2016 at 3:31
  • Looks like it should work, assuming the filesystem type allows hard links. I would try copying the script and paring it down to backup a single small directory, setting literally TODAY=today and PREVIOUS_DAY=yesterday. Run the script, then mv today yesterday, and run again. On a separate point I can recommend adding -R so that your backup tree represents exactly the source tree, eg rsync -aR /a/b/c /x will create /x/a/b/c. This also avoids differences when the source dir does or does not end in /.
    – meuh
    Jul 21, 2016 at 7:16

1 Answer 1

0

The best way to know if rsync is hardlinking simply view the disk usage from something like gparted and see if its creating large backups. it shouldn't and the --link-dest option does what it says. A hard link will appear to the rest of the system and many programs as a dulpicate copy of that data when its only a link to the same blocks of data on the actual disk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .