Learner12
Learner12

Reputation: 21

Program for Backup - Python

Im trying to execute the following code in Python 2.7 on Windows7. The purpose of the code is to take back up from the specified folder to a specified folder as per the naming pattern given.

However, Im not able to get it work. The output has always been 'Backup Failed'.

Please advise on how I get resolve this to get the code working.

Thanks.

Code :

backup_ver1.py

import os
import time
import sys

sys.path.append('C:\Python27\GnuWin32\bin')
source = 'C:\New'
target_dir = 'E:\Backup'
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip'
zip_command = "zip -qr {0} {1}".format(target,''.join(source))
print('This is a program for backing up files')
print(zip_command)

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

Upvotes: 0

Views: 479

Answers (1)

Himanshu
Himanshu

Reputation: 2454

See if escaping the \'s helps :-

source = 'C:\\New'
target_dir = 'E:\\Backup'

Upvotes: 1

Related Questions