Linux shell scripting

11 Jan

I am spending more of my time working with Linux so I’m learning some of the things you can do with it

We have a couple of NAS boxes which need to be backed up in a kind of Time Machine fashion. This is relatively easy to do with rsync (which I believe is what Apple’s Time Machine uses). I found this web site which helped me get started and this is what I ended up with. You just have to run this from cron and you get new backups each day which appear to contain the full contents of the source machine but actually only contain new files and a set of symlinks to files which are in a previous backup.


#log start time
date > /tmp/timemachine.log

#folder will be called yyyy-mm-dd
date=`date "+%Y-%m-%d"`

#backup - link it to the most recent folder
#copy from nas02
#and to a dated folder on nas01
#redirect all output to a log file
rsync -a --link-dest=/destination/current sourcemachine.fqdn.tld::source_share /destination/$date >> /tmp/timemachine.log

#remove the "current" symlink (it's not current any longer)
rm -f /destination/current

#and make a symlink to the backup we just made
ln -s /destination/$date /destination/current

#all done so log end time
date >> /tmp/timemachine.log

#and send an email
echo "Backup complete; log attached" | mutt -s "Backup complete for NAS" -a /tmp/timemachine.log -- myemail@email.tld 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: