- Feb 21, 2013
- 2,650
- 4
- 81
I'm kind of new to BASH scripting, so be gentle please 
In short, how would I write a script to find the most back-up as my hardlink target using rsync?
In detail, I've written an adorable script to back-up my main data drive to an external. I tried using rsnapshot initially, but problems with white-space in directory paths and rsnapshot not interpreting wildcard characters (like '?') in place of whitespace, so I figured what-the-heck, I'll just use rsync and hardlinks.
Here's what it looks like:
But this has an obvious problem, if I don't run it everyday, the whole today/yesteday thing doesn't work. That would be fine if I used linux exclusively, I would just add it to my cron tab, but I dual-boot ubuntu 12.04 and windows, and I don't always boot into ubuntu every day. How would I modify this script so that it looked for the most recent back-up on its own and automatically used that as a hardlink?
Additional notes (in case it matters):
1) 'source' lives on an NTFS formatted HDD. Target also lives on an NTFS formatted HDD.
2) Ubuntu's root as well as Windows7 OS/apps live on ext4/NTFS partitions of an SSD.
In short, how would I write a script to find the most back-up as my hardlink target using rsync?
In detail, I've written an adorable script to back-up my main data drive to an external. I tried using rsnapshot initially, but problems with white-space in directory paths and rsnapshot not interpreting wildcard characters (like '?') in place of whitespace, so I figured what-the-heck, I'll just use rsync and hardlinks.
Here's what it looks like:
#!/bin/bash
#I want rsync to make a new directory of today's date for
#today's backup, and I also want it to know
#the directory that stored yesterday's backup
#so it can use that as a hardlink.
NEWBACKUP=`date -I`
PREVBACKUP=`date -I -d "1 day ago"`
#I want to back-up everything inside of my data drive
#I want to make a new directory for today's back-up, and
#I want to hardlink it to the previous day's back-up.
SOURCE="/PATHTODATADRIVE/"
TARGET="/PATHTOBACKUPDRIVE/$NEWBACKUP"
HARDLINK="/PATHTOBACKUPDRIVE/$PREVBACKUP"
#I want all the archival options, I want verbose output
#so I can see if there are problems or hangups, and I'd
#like the final diagnostics in human readable units.
OPTIONS="-avh --link-dest=$HARDLINK"
rsync $OPTIONS $SOURCE $TARGET
But this has an obvious problem, if I don't run it everyday, the whole today/yesteday thing doesn't work. That would be fine if I used linux exclusively, I would just add it to my cron tab, but I dual-boot ubuntu 12.04 and windows, and I don't always boot into ubuntu every day. How would I modify this script so that it looked for the most recent back-up on its own and automatically used that as a hardlink?
Additional notes (in case it matters):
1) 'source' lives on an NTFS formatted HDD. Target also lives on an NTFS formatted HDD.
2) Ubuntu's root as well as Windows7 OS/apps live on ext4/NTFS partitions of an SSD.