• entries
17
28
• views
27434

# Crash Recovery

598 views

I recently suffered a terrible HD crash on my coding laptop, which resulted in a loss of about 2 months of coding work. Needless to say, losing any amount of work that you are proud of certainly does suck. However, I've been able to collect a list of tasks that vanished as a result of this event and I should be back on track within a week or so.

There is something positive that came out of this crash, as I have been reminded of the importance of backup up my work. For a while I was doing pretty good, using a svn repository in addition to performing full archives of the code base with a zip file. That backup regiment has slowly tapered off, and lately I've been only zipping the code base without copying the zip up to a thumb drive or external.

In response, I've written the following script that I wanted to share that performs the backup for me. If you're really bad about backing up your work, you may want to do what I did: place the script directly on your external storage device and integrate it into the autorun. Directions on doing this are included in the scripts comments:

#### file: backup.py## author: Alex Wood## date: 2008-06-04## desc: Archives all files in each specified directory into a specific zip file.###### Place this script in the toplevel of a thumb drive or external harddrive## to enable autobackup of directories, as described below.#### Copy and paste the following text into your autorun.inf text file:#### [autorun]## open=launch.bat## ACTION = Launch portable workspace#### Create launch.bat and add the following line:## python backup.py## import osimport zipfileimport datetimedirList = [('C:\\foo', 'foo'), # directory, zip name('C:\\bar', 'bar'), # directory, zip name]copyDest = os.getcwd()numFiles = 0for src in dirList: currentPath = src[0] # verify the source directory exists if not os.path.isdir(currentPath): print '%s not found' % currentPath continue # zipfile name is the concatenation of the zip name (defined in dirList) and a timestamp zipname = src[1] zipfilename = "%s_%s.zip" % (zipname, datetime.datetime.now().strftime("%Y%m%d%H%M%S")) file = zipfile.ZipFile(zipfilename , "w") for (path, dirs, files) in os.walk(currentPath): numFiles += len(files) currentPath = path for name in files: print name archiveName = str(os.path.join(path, name)) # the archive name must be relative to the root of the archive # so strip off the C:\foo part of the path archiveName = archiveName[len(src[0]):] file.write(os.path.join(path, name), archiveName, zipfile.ZIP_DEFLATED) print '%d files archived into %s' % (numFiles, zipfilename)

There are no comments to display.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account