Python Script: Backup files using 7 zip

Hello friends, below is a Python Script for taking backup of files in Windows. For using this script, you must have command line version of 7 zip installed.

import os
import time

source = 'D:\\backup_original' 
# source folder

target_dir = 'E:\\backup_copied'
# target folder
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip'

zip_command = "7za a {0} {1}".format(target, ''.join(source))

if os.system(zip_command) == 0:
    print('Backup Failed')

Linux Version:

Just replace  below line
zip_command = "7za a {0} {1}".format(target, ''.join(source))

with this one:

zip_command = "zip -r {0} {1}".format(target, ''.join(source))

There is no need to install 7zip in linux. Zip is installed in most of the distros by default.