Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This auto backups the zip and folder for tally data
#!/usr/bin/env python3
"""tally_backup.py: this auto backups the zip and folder for tally data."""
__author__ = "Jatin Kumar Malik (@jatinkmalik)"
import os
import zipfile
import shutil
import datetime
# constants
TALLY_DATA_PATH = "C:\\Users\\Public\\Tally.ERP9"
TALLY_BACKUP_ZIP_PATH = "D:\\tally_auto_backups\\zip\\"
TALLY_BACKUP_FILE_PATH = "D:\\tally_auto_backups\\file\\"
def dozip(source_folder, target_zip):
zipf = zipfile.ZipFile(target_zip, "w-")
for subdir, dirs, files in os.walk(source_folder):
for file in files:
print(os.path.join(subdir, file))
zipf.write(os.path.join(subdir, file))
print("Created zip:", target_zip)
def docopy(source_folder, target_folder):
for subdir, dirs, files in os.walk(source_folder):
for file in files:
print(os.path.join(subdir, file))
shutil.copy2(os.path.join(subdir, file), target_folder)
print("Copied files:", target_folder)
if __name__ == '__main__':
print("Starting backup for Tally 9")
dt = datetime.datetime.now()
# zip to backup folder
source_folder = TALLY_DATA_PATH
target_zip = "{0}\\{1}.zip".format(TALLY_BACKUP_ZIP_PATH, dt)
dozip(source_folder, target_zip)
# copy to backup folder
source_folder = TALLY_DATA_PATH
target_folder = "{0}\\{1}".format(TALLY_BACKUP_FILE_PATH, dt)
docopy(source_folder, target_folder)
print("Ending backup:", dt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment