How to Rescue Windows Files Using Linux and Python - The Problem: Windows Operating System is broken, must be a virus or something; need to rescue important files immediately.
The 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'
No comments
Post a Comment