Script to back up files

The following example illustrates a simple script to back up files .
The backup files are zipped with a name corresponding to the current date and time

#!/usr/bin/python
import os,sys,time
source=['/home/yeswanth/a.txt','/home/yeswanth/b.txt']
target_dir='/home/yeswanth/back/'
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
zip_command="zip -r %s %s" %(target,' '.join(source))
if (os.system(zip_command)==0):
	print 'successful backup to ',target
else :
	print 'Backup failed'

Please change the file names and the paths for the script to run

Concept and idea : borrowed from the book A Byte of Python by Swaroop C.H

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s