BradTrupp.com - Little slices of my life and my projects BradTrupp.com -- Tags -- Code
BradTrupp.com -- Tags -- Code -- A Little Bit of Automation for your Backups

A Little Bit of Automation for your Backups
(2010/02/25)

There are likely thousands of ways to backup your computers data. One I like, since it is simple, is using a batch file that calls 7zip to create a zip backup with the current date embedded in the zip file name.

This method can be described as "so 1980's" since it is done with batch or command files calling batch programs with command line parameters.

You need working copies of Ruby and 7zip installed. Both products are open-source and free.

The first piece of the puzzle is a short ruby script that does nothing more than create a one-line batch file to set an environment variable with a formatted date string for today.

#!/usr/bin/ruby -w
time = Time.new
yymmdd = time.strftime('%Y-%m-%d')
myfile = File.new("yymmdd.bat", "w+")
myfile.puts("SET YYMMDD=#{yymmdd}")
myfile.close;
puts "Set YYMMDM to #{yymmdd}"

Save this script as "set-yymmdd.rb".

Run this script and you will get a new file "yymmdd.bat" that looks like this.

SET YYMMDD=2010-02-25

If you do not understand how environment variables work in Windows command processing, you can read up on in many web sources including these articles at Microsoft Support and Wikipedia

Now the magic that pulls it all together is the final batch command script

set indir="c:\PersonalApps\*.*"
set otdir=q:\backups\
set otfil=Personal
call set-yymmdd.rb
call YYMMDD.BAT
call "C:\Program Files\7-Zip\7z.exe" a -r -tzip "%otdir%%otfil% %YYMMDD%" %indir%

In this case "c:\PersonalApps\*.*" is a directory on my computer that I want backed up. The backup is being written to a network drive that I have permanently mapped to my Q drive and it has an existing "\backups" subdirectory. The backup itself gets named "Personal 2010-02-25.zip" since I ran it on February 25th of 2010.

The current date is a part of the file name so backups done on other days will have unique names and will not accidentally overwrite.

In my case, I keep a folder on my desktop with icons to run the various backups when I want.

You could just as easily set up any scheduler program, including Windows built-in ability to run scheduled tasks, to make your backups run automatically.

Tags: Code

Share: Del.icio.us | Digg | Facebook | Google Bookmarks | Reddit | Technorati | Twitter | Windows Live | Yahoo! My Web

View Comments (0)


 

Tag: Code
A Little Bit of Automation for your Backups (2010/02/25)
A Simple CSV to iCalendar Conversion Utility written in Ruby (2009/06/29)
A Simple iCalendar to Task Coach Conversion Utility written in Ruby (2009/05/09)
Using Ruby to generate Social Bookmarks for your Web Pages (2008/11/23)
Using Ruby to fix id3 tags on mp3 files (Ruby) (2008/11/10)
Copy all files in a directory tree to a common destination. (Ruby) (2008/10/08)
Check for File Changes using Ruby and MD5 (Ruby) (2008/08/20)
Create Checkpoints using Ruby and MD5 (Ruby) (2008/07/30)
Bash - A Basic Greeting Program. (Bash) (2007/10/31)
Bash - An Introduction to Scripting (Bash) (2007/10/10)
UUMerge Command Line Text File Merge (Delphi) (2007/07/01)
Explorer-Style Fly-By Buttons (Delphi) (2006/01/14)
Handle-Free Checkboxes in a String Grid (Delphi) (2006/01/14)

All Tags
Business Tips (5)
Code (13)
Life Skills (1)
Music (2)
My 15 minutes (5)
Old Articles (39)
Photos (10)

Advertisement