News

How To: Rescue Windows Files Using Linux and Python

Problem: Windows Operating System is broken, must be a virus or something; need to rescue important files immediately.

Solution: A Linux Live CD with Python pre-installed; an external storage device; this Python Script:

#!/usr/bin/python
# Filename: backup.py
import os, time

source = [‘DIRECTORY OF WINDOWS FILES TO BE BACKED-UP!’]
target_dir = ‘LOCATION OF EXTERNAL STORAGE DEVICE!’
today = target_dir + time.strftime(‘%Y%m%d’)
now = time.strftime(‘%H%M%S’)
comment = raw_input(‘Enter a comment –> ‘)
if len(comment) == 0:
target = today + os.sep + now + ‘.zip’
else:
target = today + os.sep + now + ‘_’ + \
comment.replace(‘ ‘, ‘_’) + ‘.zip’
if not os.path.exists(today):
os.mkdir(today) # make directory
print ‘Successfully created directory’, today
zip_command = “zip -qr ‘%s’ %s” % (target, ‘ ‘.join(source))

if os.system(zip_command) == 0:
print ‘Successful backup to’, target
else:
print ‘Backup FAILED’

 Source: Tech Source From Bohol

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *