Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 330
Mahakaal Avatar asked Mar 18 '26 10:03

Mahakaal


1 Answers

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')
like image 63
zeekay Avatar answered Mar 20 '26 01:03

zeekay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!