Linux remote incremental backup

Backup is something that we should all be doing all the time. Sometimes it’s simple, other times it’s not. I’m going to deal with one of those times it seems a lot harder than it is: a remote incremental backup. Let’s say you’ve got a server with a website that other people are editing and it’s not got any version control, for whatever reason. Let’s also say that you need to back it up and provide the ability to roll back a day or two, or even to any point in its history. This seems like the sort of thing you buy an off-the-shelf product for when it’s something you can do with one simple shell script. All you need is a Subversion repository and the usual tools one finds lying about on a Linux system. I’m going to have to assume a working knowledge of Subversion for this, but if you are not familiar with the workings, there are plenty of simple tutorials on the internet that will get you up and running.

# Jared Earle, 2011-08-14, Ltd
# Set the datestamp
export date=$(date +\%Y\%m\%d)
# Server name and paths - change these to your values
export server="host.tld"
export remotepath="/path/to/remote/files"
export localpath="/path/to/local/files"
export templog="/tmp/subscript${date}.log"
# Fetch the files and push them to subversion
cd ${localpath}
echo "Backup dated ${date}
----" > ${templog}
/usr/bin/rsync -avz -e ssh ${server}:${remotepath}/ ./ >> ${templog} 2>&1
/usr/bin/svn add --force .
/usr/bin/svn commit -F ${templog} .
rm ${templog}

You need to have SSH keys set up on your local system and on your remote system so as not to require passwords every time you run the script. You also need to check out the empty repository to the directory specified in $localpath in the script and get it to store the subversion password locally.

After it’s set up, you just put this script somewhere convenient and add it to crontab to run nightly. Yes, I realise this seems far too simple, but that’s the point. It works on Linux, BSD and OSX, as far as I can tell. Any comments, questions or improvements, feel free to comment below.

Jared Earle is a writer, photographer and systems administrator. You can find him on Twitter most of the time.

Posted in geek Tagged with: , , , , ,
  • Pingback: martinjmurray()

  • Pingback: Adrián N.()

  • Pingback: Zak Mensah()

  • Pingback: Ben Wilkoff Network()

  • TronGuy

    You could probably incorporate Expect to handle the passwords thing.

    I have to say though: *very* nice solution.

  • Pingback: ravi motha()

  • chrisbtoo

    Interesting idea to use subversion, but ISTM you could one day run into a problem where you restore from a certain date and get files which had been deleted.

    Here’s what I use for local backups using rsync. Excuse nonflexibilityness.


    date=`date “+%Y-%m-%dT%H:%M:%S”`
    rsync -aP –exclude-from=/home/chrisb/backup-excludes –link-dest=$BACKUPDIR/current / $BACKUPDIR/back-$date
    rm -f $BACKUPDIR/current
    ln -s $BACKUPDIR/back-$date $BACKUPDIR/current

    Reminds me… I should run a backup.

    • chrisbtoo

      So much for the <pre> element.

  • Stef

    rdiff-backup is where’s it’s at for me: it’s stable, reliable, and easy to both backup and restore from. Works in much the same way as your script, with the majority of setup time spent configuring the SSH key automated logins. Worth a look:

  • rebecca0196

    These were very anxious hours for me as I couldn’t reach her.We all know by now that having many web sites pointing to your web site increases your Google link cheap nike blazers popularity and can score your web site higher page ranking and consequently the site will be higher in the search engine ‘natural results’.And, they not all that bad for you fat/calories wise, unless you eat an entire baguette in one sitting, like I been known to do.In school an essay enables a teacher to see how much you know, and he/she will usually grade you accordingly.Knitwear combos by LV are a great choice for fall and winter seasons.All offering the same consequence but the position is, which of these brands safeguard the hair.

    Before working for the National Football League, many have to work up the ranks through intern positions, or even worked as an area scouts.When you feel as if a customer doesn’t like your price, you simply need to remember they only fail to see the value of what you are offering.In the 1860s, though, neither Dr.What nous!acquisition begins with the physical phenomenon or physical property to be measured, including temperature, light intensity, gas pressure, fluid flow, and force.Likewise, if you decide to host it at home, you may want to supplement with extra tables, chairs, silverware, glassware, etc.

    CEO Ken Hicks explained the decline was due to lower IMUs (initial markups) as vendors passed along input cost increases, saying:These sites vary in assortment and prices.As a result, they may not scale back their spending as steeply as imagined.The result is a beautiful looking hair and a healthy scalp.I switched beds at 6am (girlfriend up for work) and was woken up anhour early by my phone going off.At A2zShoes you can entry a broad variety of sports activities footwear like Nike oxygen Jordans, Adidas, Timberlan, Bape and Lacoste to identify a few.Straight up blew the call.Thanks for that, ganstas.

    My Home Improvement Shoes Clicking Heels!Windows 2000 offers the user more advanced control over the operating system and has an interface similar to Windows 98 or Millennium.If the company fails to translate users into meaningful revenue and earnings growth, then this company is still wildly overvalued at the current multiples.Besides, trashing your feet, they Nike Air Max 2013 For Sale could induce Low Discomfort in the back, ruin your pose, affect your legs et cetera.Most four wheel drives have a snorkel fitted to stop this, but water in many other important bits of engine will have the same effect.This is because it is often made of much higher-quality fabrics, and created with more care.

    A healthy individual cannot go into ketoacidosis.If clubbing is your scene then test out the several Air Max Pas Cher great clubs in Huddersfield including the Camel Club, Tokyo, Livingstones and Billie Rox.Windows 2000 is possibly a mix between Windows 98 and Windows XP.Jordan’s performance in the shoes was nothing less than amazing.So as you can see good soccer drills for kids will have an age progression to it.Well I can tell you (as I am sure you already know) it is not easy in any way shape or form.Chamberlain attended Overbrook High School in Philadelphia.Jump with The Bryant!Introduced in the calendar year 1982, as a teaching shoe has now become an all-objective soccer shoe of alternative.