Search code examples
pythonlinuxarchive

How to make function "make_archive" to include the parent directory in python


I am using shutil.make_archive function to make archive

But it only archive the contents of directory. i have the folder to backup like root_dir = /home/john/public_html

I use that then my archive contains the contents of public_html but i want to include public_html itself in archive.

Now in my john folder i have many other folders as well that i don't want to backup so i can't use /home/john


Solution

  • You want to pass the base_dir argument, as mentioned in the docs:

    shutil.make_archive('public_html_backup', 'zip', '/home/john', '/home/john/public_html')