def decrypt_and_extract(file): if not os.path.isfile(file): print("Archive file not found: %s" % file) sys.exit(1) if file[-4:] != ".enc": print("Archive file must be encoded: %s" % file) sys.exit(1) name = os.path.basename(file) tar_path = os.path.join(temp_dir, name[:-4]) aestool.decrypt_file(aestool.get_key(password), file, tar_path) tar = tarfile.open(tar_path, "r") tar.extractall(temp_dir) tar.close() print("Decrypting and unpacking: %s" % file)
dir = os.path.join(staging_dir, md5[0:2], md5[2:4]) if not os.path.isdir(dir): os.makedirs(dir) shutil.copyfile(os.path.join(source_dir, file), os.path.join(dir, md5)) index.write(os.path.join(staging_dir, '%s.backrypt' % now_string)) if file_count == 0: shutil.rmtree(temp_dir) print('No new or modified files to backup since last backup') sys.exit(0) # Tar up staging_dir to os.path.join(temp_dir, tgz_name) tar_path = os.path.join(temp_dir, tar_name) tar = tarfile.open(tar_path, 'w:bz2') tar.add(staging_dir, arcname='staging') tar.close() # Encrypt tgz to os.path.join(temp_dir, archive_name) archive_path = os.path.join(temp_dir, archive_name) key = aestool.get_key(password) aestool.encrypt_file(key, tar_path, archive_path) # Copy the archive shutil.copyfile(archive_path, os.path.join(dest_dir, archive_name)) # Write back out the index index.write(local_cache_file) # Cleanup shutil.rmtree(temp_dir)