In [1]:
# example of usage of archive tools to compress a folder and create list of files and md5 hashes.
import shutil
import logging
from archivetools import tar as tt

logging.basicConfig(filename='backup.log', level=logging.DEBUG)

In [ ]:
# compress the contents of source_folder into a triad:
#  - session.tar.xz (tar archive with the contents of the session folder)
#  - session.mdl (csv list list of name, md5checksum of all the contents)
#  - session.md5 (just the md5checksum of the .tar.xz archive)
# located in tmp_folder/session

dest_file, md5_arch, md_list = tt.compress_folder(source_folder, tmp_folder, dest_name, mode='w:xz')

# check_list is a list of lists [name, md5 checksum]
# check_ok is True if the md5checksum of all the files in the archive
# (computed post-hoc) coincide with the ones in check_list
check_list, check_ok = tt.check_tar_archive(dest_file, md_list)

# Mind that all the files are read (chunked) several times,
# hence you want to do the compression/check in a local scratchpad
# rather than over a samba share.

# If everything checks, move the archive from tmp to its final dest.
assert (check_ok), "There were errors compressing the file"
shutil.move(tmp_folder, dest_folder)

# and If dared, actually remove the uncompressed data
#shutil.rmtree(source_folder)