create backup script in python
Rainy
sill at optonline.net
Sat Jun 9 16:28:50 EDT 2001
On 9 Jun 2001 11:26:21 GMT, Fredrik Steen <nospamnntp at stone.nu> wrote:
> On Sat, 02 Jun 2001 15:22:44 GMT, Rainy <sill at optonline.net> wrote:
>> On 1 Jun 2001 18:30:48 -0700, eric_brake <brakedon at hotmail.com> wrote:
>>> What is the easiest way to write a file copy script in python? I want
>>> to use the script as a way to backup any file I choose on my hard
>>> drive. Binary mode is best while handling this range of file types,
>>> Correct?
>>>
>>> thank you
>>
>> Backup to where? I made a little script that backs up my home directory
>> to a cdrw disk, it uses mkisofs and cdrecord (unix programs).
>>
>>
>
> Would you share your script?
>
Sure.. I think I appended it to original message but then someone snipped it.
Anyhoo, here it goes:
#!/usr/bin/env python
#-----------------------------------------------------------------------
#
#
# Send bug reports, comments to Andrei Kulakov <ak at silmarill.org>
# Last Updated: Fri Aug 11 22:03:27 EST 2000
# Copyright (C) 2000 Andrei Kulakov
#-----------------------------------------------------------------------
import os, sys
homedir = os.path.expanduser('~sill/')
# cdrw device (cdrecord argument)
dev = '0,0,0'
def print_help():
print 'backup.py script'
print 'Usage: backup.py <temp image file>'
sys.exit()
try:
image_file = sys.argv[1]
except IndexError:
print '*** Error: need one argument.'
print_help()
os.system('cp -r /etc ' + homedir)
os.system('mkisofs -R -o ' + image_file + ' ' + homedir)
os.system('cdrecord -v -blank=fast -speed=2 -dev=' + dev)
os.system('cdrecord -v -dev=' + dev + ' -speed=2 -fs=8m ' + image_file)
answer = raw_input('Erase image file? [Y/n]')
if answer == 'Y' or answer == '':
os.remove(image_file)
os.remove(homedir + '/etc')
--
Don't be so humble -- you are not that great
- Golda Meir
More information about the Python-list
mailing list