Quantcast
Channel: 'Help regarding Python backup script.' Thread RSS Feed
Viewing all articles
Browse latest Browse all 3

Re: Help regarding Python backup script.

$
0
0
: I am a newbie and currently learning python. I use a tutorial called "A Byte Of Python" and there I encountered a little problem with an example in the tutorial. It seems as he who wrote this tutorial are running on Linux and I am running on Windows. This is the code that he wrote(Swaroop C H):
:
: import os
: import time
:
: # 1. The files and directories to be backed up are specified in a list.
: source = ['/home/swaroop/byte', '/home/swaroop/bin']
: # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
:
: # 2. The backup must be stored in a main backup directory
: target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
:
: # 3. The files are backed up into a zip file.
: # 4. The name of the zip archive is the current date and time
: target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
:
: # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
: zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
:
: # Run the backup
: if os.system(zip_command) == 0:
: print 'Successful backup to', target
: else:
: print 'Backup FAILED'
: ------------------------------------------------------------------------
:
: as you can see this is a backup script who copies the the targeted files into another directory and compress them to Zip Files. My dilemma is that I cant find the windows command for compressing Zip files like they
: have in Linux/Unix, can anyone help me?

You may have to download a zip utility. There is a project at SourceForge, I think, called UnixUtils or something like that, which provides dozens of these command line utilities from Linux for your Windows machine.

Python also comes with some libraries for compression. Look in your python documentation for the modules: zipfile, zlib, gzip, and bz2. There may even be others that I'm not aware of. Basically, the point is that you should be able to compress your files directly from python without having to call an external zip command.


infidel

$ select * from users where clue > 0
no rows returned



Viewing all articles
Browse latest Browse all 3

Trending Articles